解决Mysql错误1040 Too many connections的方法

来源:互联网 发布:索尼电视推荐 知乎 编辑:程序博客网 时间:2024/05/30 05:27

解决mysql 1040错误Too many connections的方法
错误信息如下:

Can not connect to MySQL server Error: Too many connectionsErrno.: 1040

Similar error report has beed dispatched to administrator before.

从官方文档知道linux上面编译安装的mysql默认的连接为100个,这样对于网站的需求来说是远远不够的。
文档:http://dev.mysql.com/doc/refman/5.0/en/too-many-connections.html
If you get a Too many connections error when you try to connect to the mysqld server, this means that all available connections are in use by other clients.

The number of connections allowed is controlled by the max_connections system variable. Its default value is 100. If you need to support more connections, you should restart mysqld with a larger value for this variable.

MySQL官方告诉我们需要修改max_connections的值,那么我们怎么去修改呢?有两种方法

1、修改配置文件文件

修改/etc/my.cnf这个文件,在[mysqld]中新增max_connections=N,如果你没有这个文件请从编译源码中的support-files文件夹中复制你所需要的*.cnf文件为到/etc/my.cnf。我使用的是my-medium.cnf,中型服务器配置。例如我的[mysqld]的内容如下

[mysqld]port            = 3306socket          = /tmp/mysql.sockskip-lockingkey_buffer = 160Mmax_allowed_packet = 1Mtable_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mmax_connections=1000

由于对mysql还不是很熟悉,所以很多参数没有修改。哈哈。。

2、非使用mysqld脚本自动启动的用户。

修改$MYSQL_HOME/bin/mysqld_safe文件
例如:/usr/local/mysql/bin/mysqld_safe这个文件

grep -n 'max_connection' $MYSQL_HOME/bin/mysqld_safe

修改对应行号的max_connections参数值

阅读全文
0 0
原创粉丝点击