1. 程式人生 > >Ubuntu 16.04安裝MySQL,修改max_connections(連線資料庫出現``Too many connections``)

Ubuntu 16.04安裝MySQL,修改max_connections(連線資料庫出現``Too many connections``)

1.臨時修改,重新登入MySQL後失效: 登入mysql,在命令列中輸入臨時修改:set global max_connections=1000; 2. 永久修改: 2.1 開啟/etc/security/limits.conf:在文件底部加入

*		 soft 	  noproc 	 65535
*		 hard 	  noproc 	 65535
*		 soft 	  nofile 	 65535
*		 hard 	  nofile 	 65535
root 		 soft 	  noproc 	 65535
root 		 hard 	  noproc 	 65535
root 		 soft 	  nofile 	 65535
root 		 hard 	  nofile 	 65535

2.2 開啟etc/mysql/mysql.conf.d/mysqld.cnf:修改文件許可權,改為可寫(sudo chmod 777 etc/mysql/mysql.conf.d/mysqld.cnf),在檔案里加入max_connections=1000 若文件中有max_connections直接修改即可,改完後將許可權重新改為只讀(sudo chmod 644etc/mysql/mysql.conf.d/mysqld.cnf),否則該配置檔案不會生效(這也是Mysql資料庫不載入mysqld.cnf配置檔案的原因);

2.3 開啟/lib/systemd/system/mysql.service:在文件中加入

LimitNOFILE=65535
LimitNPROC=65535

2.4 在終端執行:

systemctl daemon-reload
systemctl restart mysql.service

再次進入mysql時,show variables like’max_connections’;就會顯示max_connections為1000了,想要改成其他值按第2步修改即可。 (以上2.1-2.3順序不分先後)