wait_timeout过大有弊端,其体现就是MySQL里大量的SLEEP进程无法及时释放,拖累系统性能,不过也不能把这个指设置的过小,否则你可能会遭遇到“MySQL has gone away”之类的问题,通常来说,我觉得把wait_timeout设置为10是个不错的选择,但某些情况下可能也会出问题,比如说有一个CRON脚本,其中两次SQL查询的间隔时间大于10秒的话,那么这个设置就有问题了(当然,这也不是不能解决的问题,你可以在程序里时不时mysql_ping一下,以便服务器知道你还活着,重新计算wait_timeout时间):
# vi /etc/my.cnf
[mysqld]
wait_timeout=10
# /etc/init.d/mysql restart
不过这个方法太生硬了,线上服务重启无论如何都应该尽可能避免,看看如何在MySQL命令行里通过SET来设置:
mysql> set global wait_timeout=10;
mysql> show global variables like 'wait_timeout';
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| wait_timeout | 10 |
+----------------------------+-------+
这里一个容易把人搞蒙的地方是如果查询时使用的是show variables的话,会发现设置好像并没有生效,这是因为单纯使用show variables的话就等同于使用的是show session variables,查询的是会话变量,只有使用show global variables,查询的才是全局变量。
网络上很多人都抱怨说他们set global之后使用show variables查询没有发现改变,原因就在于混淆了会话变量和全局变量,如果仅仅想修改会话变量的话,可以使用类似set wait_timeout=10;或者set session wait_timeout=10;这样的语法。
另一个值得注意的是会话变量wait_timeout初始化的问题,这一点在手册里已经明确指出了,我就直接拷贝了:
On thread startup, the session wait_timeout value is initialized from the global wait_timeout value or from the global interactive_timeout value, depending on the type of client (as defined by the CLIENT_INTERACTIVE connect option to mysql_real_connect()).
分享到:
相关推荐
Ubuntu server 讲述服务器的配置
The Ubuntu Server Edition, also called Ubuntu Server, offers support for several common configurations, and also simplifies common Linux server deployment processes. With this book as their guide, ...
Ubuntu Server 12.04安装图解,附件中为安装过程中全部截图,可按照图中所选择部分安装
本文档简单的阐述了如何在Ubuntu18.04安装mysql,并成功的启动mysql,笔者是window 10 和Ubuntu的双系统,为了方便就安装了个mysql
ubuntu修改mysql密码,记录一下吧
在ubuntu下安装mysql服务器 以及导入数据库的方法 还有设置双机热备份
ubuntu 15.04开放mysql远程3306端口
ubuntu 1204 server guide
在Ubuntu Server系统安装完成后默认没有使用network-manager管理网络,此文章简单介绍了如何使用network-manager管理网络。
从mysql官网上下载mysql-server_5.7.21-1ubuntu14.04_amd64.deb-bundle.tar,然后进行离线安装,解压该安装包,会出现11个依赖包,按照顺序依次使用sudo dpkg -i 进行安装,中间会报错,显示缺少相应的依赖,具体...
Ubuntu Server最佳方案[高清完整PDF版].pdf
Ubuntu Server64位系统安装Odoo10
手动在Ubuntu系统下安装指定版本mysql,
Ubuntu18.0.4安装mysql5.7.25后无法登陆如何处理
Ubuntu Server is a complete, free server operating system that just works, with the extra Ubuntu polish, innovation, and simplicity that administrators love. Now, there’s a definitive, ...
Ubuntu Server安装和配置手册
Administer Ubuntu Server in the EnterpriseRealize a dynamic, stable, and secure Ubuntu Server environment with expert guidance, tips, and techniques from a Linux professional. Ubuntu Server ...
mysql-ubuntu14.04系统版
Ubuntu18.0.4安装MySQL,修改ROOT用户密码并允许远程访问,添加用户并配置数据库的访问权限
该文档主要是对ubuntu server 安装的一个大致过程