mysql 连接慢的问题

Wesley13
• 阅读 436

现象:
今发现站点訪问数据库变慢,经查,查询数据库非常快,连接数据库比較耗时。

解决的方法:
在mysql的配置文件my.cnf中,在[mysqld]以下加上这个配置就能够了.

附录:[mysqld]部分要增加一个參数skip-name-resolve :主机名不被解析。增加后在授权表的 Host 的列值必须是IP数字或 localhost 。

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

点赞
收藏
评论区
推荐文章
Easter79 Easter79
2年前
tcp_tw_recycle参数引发的数据库连接异常
【问题描述】开发反馈有个应用在后端数据库某次计划性重启后经常会出现数据库连接异常问题,通过监控系统的埋点数据,发现应用连接数据库异常有两类表现:  其一:连接超时  <spanstyle"backgroundcolor:FFFF00"131148.00msTomcatConnectionPool</span  其二:连接耗时过
Wesley13 Wesley13
2年前
MySQL数据库优化技巧
MySQL优化三大方向①优化MySQL所在服务器内核(此优化一般由运维人员完成)。②对MySQL配置参数进行优化(my.cnf)此优化需要进行压力测试来进行参数调整。③对SQL语句以及表优化。MySQL参数优化1:MySQL默认的最大连接数为100,可以在mysql客户端使用以下命令查看mysql
Wesley13 Wesley13
2年前
mysql 读写分离主从复制
一.master主服务器的配置1找到主服务器mysql的配置文件windows(my.ini)linux(/etc/my.cnf)在mysqld中添加:serverid1log_binmasterbinlog_bin_indexmasterbin.indexbinlog_
Wesley13 Wesley13
2年前
MySQL查看最大连接数和修改最大连接数
1、查看最大连接数showvariableslike'%max\_connections%';2、修改最大连接数setGLOBALmax\_connections200;以下的文章主要是向大家介绍的是MySQL最大连接数的修改,我们大家都知道MySQL最大连接数的默认值是100,这个数值对于并发连接很多的数据库的应用是
Wesley13 Wesley13
2年前
mysql,基础命令
一 配置文件\mysqld\\设置mysql的安装目录\\后面的路径一定是安装sql的目录(自己电脑的)\\basedirC:\\mysql5.7.22winx64\\mysql5.7.22winx64\设置mysql数据库的数据的存放目录,必须是datadatadirC:\\mysql5.7
Wesley13 Wesley13
2年前
mysql设置远程访问
(1)连接数据库mysqlurootp(2)输入密码(3)切换数据库usemysql;(4)修改root用户hostupdateusersethost'%'whereuser'root';(5)修改mysqld配置文件vi/etc/mysql/mysql.co
Wesley13 Wesley13
2年前
Mysql数据基本操作(增、删、改、查)
一、数据库配置通过配置文件统一配置的目的:统一管理服务端(mysqld)、客户端(client)1.配置mysqld(服务端)的编码为utf8,再创建数据库的时候,默认编码都采用了utf8.配置流程:1)在mysql安装根目录下,创建配置文件:my.ini
Wesley13 Wesley13
2年前
LINUX下 解决MYSQL区分大小写问题
MySQL在Linux下采用rpm方式安装后默认是:数据库名与表名\\表的别名\\变量名是严格区分大小写 修改大小写的方法:1.用root帐号登录,在/etc/my.cnf或/etc/mysql/my.cnf中的\mysqld\后添加lower\_case\_table\_names1 操作命令:vi/e
Wesley13 Wesley13
2年前
thinkphp 基本配置
12returnarray(34//定义数据库连接信息5'DB\_TYPE''mysql',//指定数据库是mysql67'DB\_HOST''localhost',89'DB\_NAME''uchome',//数据库名1011'DB\_USER''root
Wesley13 Wesley13
2年前
Mysql重置root密码遇到的坑(忘记密码)
1、原理通过配置参数“skip\_grant\_tables”在mysql启动时跳过grant\_tables(授权表),从而通过命令来充值root帐号的密码2、方式首先需要停止mysql服务(1)在my.ini文件的\mysqld\块下增加“skip\_gran