Disable MySQL for domain name resolution (it is slow to remotely access MySQL)

Source: Internet
Author: User
Tags reverse dns

When you remotely access MySQL, MySQL will resolve the domain name, resulting in slow access. The following configuration can solve this problem.

Disable MySQL for domain name resolution
[Mysqld]

Skip-name-resolve

PHP remote connection to MySQL is slow. Sometimes it takes 4-20 seconds to remotely connect to MySQL, and the local connection to MySQL is normal. The main cause of this problem is that the reverse DNS resolution is enabled for MySQL installed by default, in my. INI (in Windows) or my. add skip-name-resolve to [mysqld] of the CNF (Unix or Linux) file.

However, this will cause a problem: when connecting to MySQL, you cannot use localhost to connect, but instead use an IP address. If you grant permissions to users by localhost, you must modify the user logon permission.

Slow connection to MySQL.

2 servers, 1 running IIS + PHP, and 1 running mysql. Configure the environment as before and test the page. Everything is OK.

When I ran the application, I found that PHP was slow to access mysql. This was never found before. Although the two servers are not in the same network segment, the ping value is basically between 1 and 2 ms, TCP connection should not be a problem. Google will find the answer later, in my. in the [mysqld] section of the INI file, add skip-name-resolve, save the file, and restart mysql. Everything is OK, and the speed is the same as flying.

The configuration of the new version of MySQL is not as foolish as it was before. It took me a long morning to solve this problem. I finally came back at night and learned something.

On the MySQL 5 Server in Windows 2003, the local machine is connected to the MySQL service very quickly. There are two Linux machines in the LAN, one of which is quickly connected, and the other one enters the password and takes several seconds to connect.

Solution:

Add the following configuration in the configuration of the MySQL server to speed up.

[Mysqld]
Skip-name-resolve

Appendix :( 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 with -- skip-name-resolve. In this case you can however only use IP names in the MySQL privilege tables.

If you have a very slow DNS and have hosts, you can get more performance by either disabling DNS lookop with -- skip-name-resolve 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 do this by starting mysqld with -- skip-networking.

PHP remote connection to MySQL is slow. Sometimes it takes 4-20 seconds to remotely connect to MySQL, and the local connection to MySQL is normal. The main cause of this problem is that the reverse DNS resolution is enabled for MySQL installed by default, in my. INI (in Windows) or my. add skip-name-resolve to [mysqld] of the CNF (Unix or Linux) file.

Slow MySQL remote connection
When I connect to MySQL from other machines in the LAN, I find that the speed is very slow. I don't know why, there will always be several seconds of delay.

Later, I found a solution on the Internet, and added it to my. ini.

CopyCode The Code is as follows: [mysqld]
Skip-name-resolve
Skip-grant-tables

This is faster!

Skip-name-resolve

To disable DNS resolution, and the connection speed is much faster. However, in this case, the host name cannot be used in the MySQL authorization table, but only in IP Format.

If you use the-Skip-grant-tables system, no access control is required for any user's access. However, you can use mysqladmin flush-privileges or mysqladmin reload to enable access control; by default, the show databases statement is open to all users,

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