转载至:http://www.oschina.net/code/snippet_222150_12958
我们大家都知道MySQL数据库在安装完之后,默认的MySQL数据库,其最大连接数为100,一般流量稍微大一点的论坛或网站这个连接数是远远不够的,增加默认MySQL连接数的方法有两个。
方法一:
03 | 进入MySQL安装目录 打开MySQL配置文件 my.ini 或 my.cnf查找 max_connections=100 修改为 max_connections=1000 服务里重起MySQL即可 |
09 | MySQL -uusername -ppassword
|
13 | MySQL>
set GLOBAL
max_connections=200 |
17 | MySQL> show processlist
|
25 | 查看当前MySQL最大连接数:MySQLadmin -uusername -ppassword variables |
29 | 以centos 4.4 下面的MySQL 5.0.33 手工编译版本为例说明: |
31 | vi /usr/ local /MySQL/bin/MySQLd_safe
|
33 | 找到safe_MySQLd编辑它,找到MySQLd启动的那两行,在后面加上参数 : |
35 | -O max_connections=1500
|
41 | then
$NOHUP_NICENESS $ledir/$MySQLD |
46 | -O max_connections=1500
|
48 | eval
"$NOHUP_NICENESS $ledir/$MySQLD |
49 | $defaults --basedir=$MY_BASEDIR_VERSION
|
50 | --datadir=$DATADIR $USER_OPTION
|
52 | --skip-external-locking $args
|
53 | -O max_connections=1500 >>
|
58 | # service MySQLd restart
|
59 | # /usr/ local /MySQL/bin/MySQLadmin -uroot -p variables
|
63 | max_connections 1500 即新改动已经生效。 |
69 | 解开MySQL的原代码,进入里面的sql目录修改MySQLd.cc找到下面一行: |
71 | { "max_connections" , OPT_MAX_CONNECTIONS,
|
72 | "The number of simultaneous clients allowed." , (gptr*) &max_connections,
|
73 | (gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 100, 1, 16384, 0, 1,
|
78 | { "max_connections" , OPT_MAX_CONNECTIONS,
|
79 | "The number of simultaneous clients allowed." , (gptr*) &max_connections,
|
80 | (gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 1500, 1, 16384, 0, 1,
|
83 | 存盘退出,然后./configure ;make;make install可以获得同样的效果。以上的相关内容就是对修改MySQL最大连接数的3种方法的介绍,望你能有所收获。 |