Share 3 ways to modify the maximum number of connections MYSQL has
- 2020-05-10 23:01:23
- OfStack
Method 1: go to the MYSQL installation directory and open the MYSQL configuration file my.ini or my.cnf to find max_connections=100 =100 max_connections=1000
The first method is recommended, which is more convenient to modify.
Method 2: the maximum number of connections for MySQL is 100 client logins by default: mysql-uusername-ppassword
Set the new maximum number of connections to 200: mysql > set GLOBAL max_connections=200
Displays Query: mysql currently running > show processlist
Display current status: mysql > show status
Exit client: mysql > exit
View the current maximum number of connections: mysqladmin-uusername-ppassword variables
Method 3: take the manually compiled version of mysql 5.0.33 below centos 4.4 as an example:
vi /usr/local/mysql/bin/mysqld_safe
Go to safe_mysqld, edit it, find the two lines that mysqld started, and add the following parameters:
-O max_connections=1500
One specific point is the following position:
In red letters:
then $NOHUP_NICENESS $ledir/$MYSQLD
$defaults --basedir=$MY_BASEDIR_VERSION
--datadir=$DATADIR $USER_OPTION
--pid-file=$pid_file
--skip-external-locking
-O max_connections=1500
> > $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=1500 > >
$err_log 2 > &1"
Save.
# service mysqld restart
# /usr/local/mysql/bin/mysqladmin -uroot -p variables
Enter the password for the root database account and you will see it
max_connections 1500 the new change has come into effect.
There's one other way,
Modify the original code:
Open the MySQL source code, go to the sql directory inside and modify mysqld.cc find the following line:
{"max_connections", OPT_MAX_CONNECTIONS,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 100, 1, 16384, 0, 1,
0},
Change it to:
{"max_connections", OPT_MAX_CONNECTIONS,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 1500, 1, 16384, 0, 1,
0},
Save and exit, then./configure; make; make install can achieve the same effect.