打开云服务器的MySQL数据库表很慢
远程连接MYSQL速度慢,有时远程连接到MYSQL用时4-20秒不等,本地连接MYSQL正常。
出现这种问题的主要原因是,默认安装的 MYSQL开启了DNS的反向解析。
解决方法:
在my.ini(WINDOWS系统下)或my.cnf(UNIX或LINUX系统下)文件的[mysqld]下加入 skip-name-resolve 这一句。
连接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 --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.
my.ini里面添加
[mysqld]
skip-name-resolve
skip-grant-tables
这样速度就快了!
skip-name-resolve
选项就能禁用DNS解析,连接速度会快很多。 不过,这样的话就不能在MySQL的授权表中使用主机名了而只能用ip格式。
若使用–skip-grant-tables系统将对任何用户的访问不做任何访问控制,但可以用 mysqladmin flush-privileges或mysqladmin reload来开启访问控制; 默认情况是show databases语句对所有用户开放,
如果mysql服务器没有开远程帐户,就在my.ini里面加上skip-grant-tables
附,请根据情况开放
skip-name-resolve 一般我们只要这一项便可以
skip-grant-tables
出现这种问题的主要原因是,默认安装的 MYSQL开启了DNS的反向解析。
解决方法:
在my.ini(WINDOWS系统下)或my.cnf(UNIX或LINUX系统下)文件的[mysqld]下加入 skip-name-resolve 这一句。
连接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 --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.
my.ini里面添加
[mysqld]
skip-name-resolve
skip-grant-tables
这样速度就快了!
skip-name-resolve
选项就能禁用DNS解析,连接速度会快很多。 不过,这样的话就不能在MySQL的授权表中使用主机名了而只能用ip格式。
若使用–skip-grant-tables系统将对任何用户的访问不做任何访问控制,但可以用 mysqladmin flush-privileges或mysqladmin reload来开启访问控制; 默认情况是show databases语句对所有用户开放,
如果mysql服务器没有开远程帐户,就在my.ini里面加上skip-grant-tables
附,请根据情况开放
skip-name-resolve 一般我们只要这一项便可以
skip-grant-tables
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了