Prevent MySQL from doing domain name resolution (remote access MySQL is slow to solve) _mysql

Source: Internet
Author: User
Tags flush save file
When MySQL is accessed remotely, MySQL resolves the domain name, resulting in slow access, plus the following configuration to resolve the problem

Prevent MySQL from doing 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

Copy Code code as follows:

[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,

If the MySQL server does not open a remote account, add skip-grant-tables to the My.ini
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.