The method of mysql_connect is slow to open the connection
- 2020-05-10 23:03:35
- OfStack
[mysqld]
skip-name-resolve
The configuration file under linux is /etc/ my.cnf, and the windows configuration file under mysql is my.ini in the mysql installation directory. Note that this configuration is added under [mysqld]. After changing the configuration and saving it, restart mysql and test the remote connection. The official explanatory information 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 calls, 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 host starting starting mysql mysql mysql mysql mysql mysql mysql mysql mysql mysql mysql mysql mysql mysql
If you have a very slow DNS and many hosts, you can more performance by either with skip with skip name resolve or HOST_CACHE_SIZE define (default: 128) and recompile mysqld
You can disable hostname cache with. You clear with HOSTS HOSTS HOSTS HOSTS hosts
If don t to over TCP/IP, you by with with with with with with with with with with with skip-networking
according to the documentation, if your mysql host query DNS is slow or if there are many client hosts, the connection will be slow. Since our development machine cannot connect to the external network, DNS parsing is impossible, so we can understand why the connection is so slow. Also, note that after this configuration parameter is added, the host field in the mysql authorization table will no longer be able to use the domain name but only the ip address, as this is the result of domain name resolution being disabled.