mysql is not allowed to do domain name resolution when of resolves remote access to mysql

  • 2020-05-09 19:28:32
  • OfStack

When mysql is accessed remotely, mysql resolves the domain name, resulting in slow access, which can be resolved by the following configuration

mysql is not allowed to do domain name resolution
[mysqld]

skip-name-resolve


The speed of PHP remote connection to MYSQL is slow, sometimes the remote connection to MYSQL takes between 4 and 20 seconds, and the local connection to MYSQL is normal. The main reason for this problem is that the default installation of MYSQL turns on the reverse resolution of DNS, and skip-name-resolve is added under the [mysqld] file of MY.INI (WINDOWS system) or MY.CNF (UNIX or LINUX system).

However, this can cause one problem: when connecting to mysql, you can no longer use localhost to connect, but use the IP address instead. If the user is authorized by localhost, the user login permission will also be modified by 1.

Slow solution for connecting mysql.

2 servers, 1 set of running iis+php, 1 set of running mysql, and the previous 1 sample configuration environment, test page 1 cut OK

While on a running application php access mysql speed is slow, this kind of situation has never been found before, although the two servers are not on the same network segment 1, but mostly ping value between 1, 2 ms, tcp connection should not key problem, google after find out, in my. [mysqld] ini file that: skip - name - resolve, save the file, restart mysql, 1 OK, cutting speed like fly 1 sample

The configuration of the new version of mysql is not like the previous one. This problem has been bothering me for a long time in the morning, but when I come back in the evening, I have finally solved it.

MySQL 5 server under Windows 2003. This machine connects to MySQL service very quickly. There are two Linux machines in the LAN.

Solutions:

Adding one of the following configurations to the MySQL server configuration is fast.

[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 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 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 many 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.

The speed of PHP remote connection to MYSQL is slow, sometimes the remote connection to MYSQL takes 4-20 seconds, while the local connection to MYSQL is normal. The main reason for this problem is that the default MYSQL installation turns on the reverse resolution of DNS, and skip-name-CNF (UNIX or LINUX) file [mysqld] 2EN.

Slow solution for MYSQL remote connection
When I connected MYSQL to other machines in the LAN, I found the speed was very slow. For some reason, there was always a delay of several seconds.

Later, I found the solution on the Internet,my.ini added


[mysqld] 
skip-name-resolve 
skip-grant-tables 


That's faster!

skip-name-resolve

The option disables DNS parsing and the connection is much faster. However, you cannot use the hostname in the MySQL authorization table but only in the ip format.

If you use the wow-skip-grant-tables system, you will not have any access control for any user, but 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 articles: