MySQLデータベースのリモート接続が遅いソリューション

2144 ワード

ある同僚が開発に使用したMySQLデータベースの接続が遅いと提案しました.私たちのMySQL開発データベースは1台の機械で配置されているので、ネットワーク接続の問題が原因かもしれないと思っています.
pingとrouteを行った後にネットの通信がすべて正常なことを発見して、その上MySQLの機械の上でローカルの接続を行って発見するのはとても速くて、だからネットの問題は基本的に排除されました.以前にも一度このような問題に遭遇したことがありますが、その後どうしたら急に良くなったのか、今回はまたこのような問題に遭遇したので、MySQLの構成の問題かどうか見てみたいです.MySQL関連ドキュメントとネットワーク検索を検索すると、MySQLのプロファイルに次の構成パラメータを追加することで、このような問題を解決できるようになりました.

[mysqld]

skip-name-resolve


Linuxでのプロファイルは/etc/my.cnf、windowsの下のプロファイルはMySQLインストールディレクトリの下のmyです.iniファイル.注意この構成は[mysqld]の下に追加され、構成を変更して保存した後、mysqlを再起動し、リモート接続テストを再開し、すべてが元のように回復します.このパラメータの公式解釈情報は以下の通りです.

   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 �Cskip-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 �Cskip-name-resolve or by increasing the HOST_CACHE_SIZE define (default: 128) and recompile mysqld.

You can disable the hostname cache with �Cskip-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 �Cskip-networking.


ドキュメントの説明によると、mysqlホストがDNSをクエリーするのが遅い場合や、多くのクライアントホストがある場合、接続が遅い場合があります.私たちの開発機器は外部ネットワークに接続できないため、DNS解析は完了できません.なぜ接続が遅いのかがわかります.また、この構成パラメータを追加すると、mysqlのライセンステーブルのhostフィールドではドメイン名を使用できず、ipアドレスのみを使用できるようになります.これはドメイン名解析が禁止された結果です.