修改mysql的最大连接数

mysql 5.0的默认最大连接数为100, 对于大负载量的并发需求可能不够,这时你可以修改mysql的最大连接。
查看mysql的当前最大连接数:
mysqladmin -uroot -ppassword variables | grep max_connections
或者
mysql> SHOW GLOBAL VARIABLES WHERE Variable_name='max_connections';

修改方法有如下几种

1.
mysql> SET GLOBAL max_connections=1000;

修改后会立即生效,不需要重启mysql服务,但是重启后会失效。

2.修改/etc/my.cnf,
在[mysqld] 下面添加:
max_connections=1000

修改后需要重启mysql服务才会重效。
结合第1和第2种方法,可以实现修改立即生效,以后重启也会有效。

3.修改/usr/bin/mysqld_safe
将下面的内容
if test -z "$args"
then
$NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-external-locking >> $err_log 2>&1
else
eval "$NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-external-locking $args >> $err_log 2>&1"

改为(添加红色字体的内容):
if test -z "$args"
then
$NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-external-locking   -O max_connections=1000 >> $err_log 2>&1
else
eval "$NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-external-locking $args -O max_connections=1000 >> $err_log 2>&1"

修改后重启mysql服务后有效。

建议用第一和第二种方法进行修改。