How to solve the Mysql database connection in LAN slow _mysql

Source: Internet
Author: User
Tags flush save file

Through the intranet even another machine MySQL service, do find speed n slow!  Wait about dozens of seconds to wait until the prompt to enter a password.  But ping MySQL's server is very fast! Think a long time ago had similar experience, telnet and some other services in connection with the request, will do some reverse domain name resolution (if the reverse parsing is not smooth, estimated will be delayed a lot, give people the feeling is the connection speed n slow!) )
Search on the Internet for the next solution, found that there are two kinds:

A. The machine configuration of both sides of the resolve.conf is not the same, the resolve.conf configured to faster DNS on OK

two. Turn off the DNS reverse resolution in MySQL configuration, OK

I use the first method, modify the resolve.conf configuration, the speed comes up!

Annex I: Excerpted from http://gcoder.blogbus.com/logs/31907502.html

Two machines in the same network segment, connect the same database server, one speed is another 100 times times, the database host is the domain name representation. Why don't you get it?

Later look at the two machines/etc/resolv.conf, found that the configuration is not the same, changed to the speed of the machine configuration, speed that on the up.

Domain name resolution can also lead to slow network procedures, but also a harvest. In addition, MySQL also has DNS reverse resolution problem, may also lead to slow, can be in the MySQL configuration file, the DNS reverse resolution turned off.

Annex II: excerpted from

When MySQL is accessed remotely, MySQL resolves the domain name, resulting in slow access, plus the following configuration to resolve the problem

 # prohibit MySQL do domain name resolution
  [MYSQLD]
  skip-name-resolve

PHP remote connection MySQL speed is slow, sometimes remote connection to the MySQL time of 4-20 seconds, local connection MySQL normal, the main reason for this problem is that the default installation of MySQL opened the DNS reverse resolution, in My.ini (Windows system) or my.cnf (Unix or Linux system) files under [mysqld] to add skip-name-resolve this sentence.

However, this will cause a problem: When you connect to MySQL, you can not use the localhost connection, but to use the IP address, if you press localhost to assign permissions to the user, the user login rights also need to modify.

a solution that connects to MySQL at a slow speed.

2 servers, a running iis+php, a running MySQL, and the same as ever configured the environment, testing the page all OK

Run application when found PHP access to MySQL is slow, this situation has never been found before, although 2 servers are not in the same network segment, but the ping value is basically between 1,2ms, TCP connection should not be the crux of the problem, Google to find the answer, in the My.ini file [Mysqld] Part add: skip-name-resolve, save file, restart MySQL, everything OK, speed is like flying

The new version of the MySQL configuration is not the same as the previous fool, this problem toss me a morning time, the evening came back finally is solved, hey, and learn something.

MySQL 5 server under Windows 2003, this machine connects to the MySQL service very fast, the LAN has two Linux machines, there is a fast connection, another input password after several seconds to connect.

Solution:

The configuration of the MySQL server adds one of the following configurations and is fast.

[Mysqld]
  Skip-name-resolve

Appendix: (How MySQL uses DNS)

When a new thread connects to Mysqld, Mysqld'll spawn a new thread to handle the request. This thread would be the hostname is in the hostname cache. If not the thread would call Gethostbyaddr_r () and Gethostbyname_r () to resolve the hostname.
If the operating system doesn ' t support the above Thread-safe calls, the thread would lock a mutex and call gethostbyaddr () and gethostbyname () instead. Note ' In ' This case no other thread can resolve the other hostnames so is isn't in the hostname cache until the D is ready.
You can disable DNS host lookup by starting mysqld with--skip-name-resolve. In this case you can however only use IP names in the MySQL privilege tables.
If you are have a very slow DNS and many hosts, you can get more performance by either disabling DNS Lookop with--skip-name-r Esolve or by increasing the Host_cache_size define (default:128) and recompile mysqld.
You can disable the hostname cache with--skip-host-cache. You can clear the hostname cache with FLUSH HOSTS or mysqladmin flush-hosts.
If you don ' t want to allow connections over TCP/IP, you can does this by starting mysqld with--skip-networking.

PHP remote connection MySQL speed is slow, sometimes remote connection to the MySQL time of 4-20 seconds, local connection MySQL normal, the main reason for this problem is that the default installation of MySQL opened the DNS reverse resolution, in My.ini (Windows system) or my.cnf (Unix or Linux system) files under [mysqld] to add skip-name-resolve this sentence.

MySQL remote connection slow speed solution

In the LAN to connect other machines MySQL, found that the speed is very slow, do not know what the reason, there are always a few seconds delay.

Later found in the online solution, My.ini inside add

  [Mysqld]
  Skip-name-resolve
  Skip-grant-tables

The speed is fast!

 Skip-name-resolve

Option to disable DNS resolution, the connection speed is much faster. However, in this way, you cannot use the hostname in the MySQL authorization table, but only in IP format.

Using the –skip-grant-tables system will not make any access control to any user's access, but you can use mysqladmin flush-privileges or mysqladmin reload to open access control; The databases statement is open to all users, and if the MySQL server does not open a remote account, add skip-grant-tables to the My.ini

Through the above methods to successfully solve the local area network MySQL database connection slow, the need for friends can refer to this article.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.