Slow remote connection to mysql (mysql_connect slow connection) _ MySQL

Source: Internet
Author: User
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

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.