首先我上次centos7.x 源碼安裝mysql未調優,同事在使用過程中報MySQL 1040 錯誤 Too many connections提示意思是說連接過多,通常有兩種原因
兩種方法
第一種:命令行修改
優點:即時生效
缺點:重啓後失效
>mysql -uuser -ppassword(命令行登錄MySQL)
mysql>show variables like 'max_connections';(查可以看當前的最大連接數)
msyql>set global max_connections=1000;(設置最大連接數爲1000,可以再次查看是否設置成功)
mysql>exit(推出)
我當前的最大連接數爲151;
修改後爲1000;
第二種:配置文件修改
優點:重啓後依然生效
缺點:需要重啓
我原來的my.cnf配置文件,請大家看好版本
[root@server-mysql ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_connections = 1000
參考: https://dev.mysql.com/doc/refman/5.7/en/too-many-connections.html 官網手冊