1、查看最大连接数
mysql> show variables like 'max_connections';
默认连接数为151
2、修改最大连接数
/etc/mysql/mysql.conf.d/mysqld.cnf
[mysql]
max_connections = 10000
3、重启确认状态
service mysql restart
执行【1】操作后,结果为214,非配置文件中设置10000
查询日志发现
65 2018-12-19T03:40:41.567706Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 50000)
66 2018-12-19T03:40:41.567763Z 0 [Warning] Changed limits: max_connections: 214 (requested 10000)
67 2018-12-19T03:40:41.567768Z 0 [Warning] Changed limits: table_open_cache: 400 (requested 2000)
4、查看系统limit限制
# 查询文件限制
$ ulimit -n
1024
5、修改系统限制
- 在/etc/security/limits.conf最后增加如下两行记录
* hard nofile 65535 * soft nofile 65535
- 编辑/etc/pam.d/common-session,加入一行
session required pam_limits.so
- 编辑/etc/profile,加入
执行cource 命令使配置生效ulimit -SHn 65535
- 确认修改是否成功
执行【4】命令,返回65535,系统限制修改成功
6、再次重启确认状态
重复【3】操作后,发现仍为 214, 问题出在mysql.service配置上
7、修改mysql配置
- 查找mysql.service 启动文件
$ systemctl status mysql.service ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2018-12-19 23:53:28 CST; 16min ago Process: 25857 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS) Process: 25843 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 25856 (mysqld) Tasks: 28 (limit: 4915) Memory: 185.9M CPU: 1.577s CGroup: /system.slice/mysql.service └─25856 /usr/sbin/mysqld
- 在mysql.service中追加以下配置
LimitNOFILE=65535 LimitNPROC=65535
8、重启确认
END
ps:mysql log 时间戳默认采用UTC,使用时应修改为系统时区
配置查询:mysql> show variables like 'log%';
配置修改:
mysql> SET GLOBAL log_timestamps = SYSTEM; -- 立即生效,重启失效
在配置文件中添加 log_timestamps=SYSTEM # 永久生效