使用MySQL時候,遇到如下報錯:Can not connect to MySQL server. Too many connections。
解決辦法:修改MySQL最大連接數。
1 打開MySQL的配置文件:
vi /etc/my.cnf
2 加入max_connections=500一行
(如果有該行,直接修改值即可)。
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html #需要主從服務器時,放開此處配置 begin [mysqld] #log-bin=mysql-bin #[必須]啟用二進制日志 #server-id=138 #[必須]服務器唯一ID,默認是1,一般取IP最后一段 #需要主從服務器時,放開此處配置 end lower_case_table_names=1 [client] default-character-set=utf8 [mysqld] character-set-server=utf8 default-time_zone = '+8:00' max_connections=500 # # 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 # # Remove leading # to set options mainly useful for reporting servers.
3 重啟MySQL服務:
service mysqld restart