Solve the problem of slow remote connection to mysql (mysql_connect slow connection) bitsCN.com finds that network communication is normal after ping and route, and it is very fast to perform local connection on the mysql machine, therefore, network problems are basically ruled out. I have encountered such a problem before, but I don't know how to make it happen. this time I encountered such a problem, so I want to see if it is a mysql configuration problem. After querying mysql related documents and network searches, a configuration seems to be able to solve this problem, that is, add the following configuration parameters to the mysql configuration file:
[Mysqld]
Skip-name-resolve
In linux, the configuration file is/etc/my. cnf, and in windows, the configuration file is the my. ini file under the mysql installation directory. Note that this configuration is added under [mysqld]. after you change the configuration and save the configuration, restart mysql and remotely connect to the mysql instance for testing. The official explanation of this parameter is as follows:
How MySQL uses DNS
When a new thread connects to mysqld, mysqld will spawn a new thread to handle the request. this thread will first check if the hostname is in the hostname cache. if not the thread will call gethostbyaddr_r () and gethostbyname_r () to resolve the hostname.
If the operating system doesn't support the above thread-safe call, the thread will lock a mutex and call gethostbyaddr () and gethostbyname () instead. note that in this case no other thread can resolve other hostnames that is not in the hostname cache until the first thread is ready.
You can disable DNS host lookup by starting mysqld