新加的一台服务器,连接内网中的一台mysql服务器的时候,经常出现超时。
登陆到mysql,查看进程的信息代码如下:
show processlist;
发现大量的进程的状态为 login
原来默认的时候mysql启动时是不使用 skip-name-resolve选项的,这样的话,从其它主机的连接会比较慢,因为mysql会对这个ip做dns反向查询,导致大量的连接处于 login状态....
.
解决这个问题有两个办法
一是加入 skip-name-resolve参数重启mysql
二是在 /etc/hosts中加入一句 192.168.0.2 server2 其中 192.168.0.2是新加的服务器的内网ip,server2是新服务器的主机名
在mysql客户端登陆mysql服务器的登录速度太慢的解决方案一篇文章中,我介绍了如何通过在my.ini文件(linux下是my.cnf文件)中添加"SKIP-NAME-RESOLVE"的参数设置,使得客户端在登录服务器的时候不通过主机解析这一关,直接登陆的方法,以此来提高登录速度。
这里要介绍一下这种方法的负面作用,以及不合理的时机使用这种方法会引发的不可发现的错误。
首先,回顾一下在my.ini文件中添加"SKIP-NAME-RESOLVE"参数来提高访问速度的原理:
在没有设置该参数的时候,客户端在登陆请求发出后,服务器要解析请求者是谁,经过解析,发现登录者是从另外的电脑登录的,也就是说不是服务器本机,那么,服务器会到mysql.user表中去查找是否有这个用户,假设服务器IP是192.168.0.1,而客户机的IP是192.168.0.2;那么查询的顺序是先找'root'@'192.168.0.2'这个user是否存在,若存在,则匹配这个用户登陆,并加载权限列表。若没有该用户,则查找'root'@'%'这个用户是否存在,若存在,则加载权限列表。否则,登录失败。
在设置了SKIP-NAME-RESOLVE参数后,客户端的登录请求的解析式同上面一样的,但是在服务器本机的解析过程却发生了改变:服务器会把在本机登录的用户自动解析为'root'@'127.0.0.1';而不是'root'@'localhost';这样一来就坏了,因为我们在服务器上登录是为了进行一些维护操作,但是显然,'root'@'127.0.0.1'这个用户是被默认为'root'@'%'这个用户的,这个用户还没有足够得权限去执行一些超级管理员'root'@'localhost'才能执行的大作。因为未分配权限。
所以结论是:加入你在服务器本机上登录mysql服务器的话,要么先取消SKIP-NAME-RESOLVE的参数设置,重新启动服务器再登陆,设置完成后,再设置上该参数;要么就给'root'@'127.0.0.1'分配超级管理员权限,但这么做显然是不明智的,因为任何人在任何机器上都可以用这个用户执行管理员操作,前提是知道了密码。
我有一次在mysql服务器上执行数据库创建脚本,并同时创建表、触发器、存储过程等。结果,总是失败,经过了一上午的折腾,最后发现时这个参数造成我以'root'@'127.0.0.1'这个用户登陆了服务器,这个用户没有创建触发器的权限。后来,取消了SKIP-NAME-RESOLVE参数后,执行成功,再把该参数设置回去。重启。OK。
所以,在设置这个参数的时候一定要注意时机:先用超级管理员将所有的用户创建好,再将权限分配好之后,才设置这个参数生效。

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software