MySQL之修改max_connections

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

注意:MySQL版本是5.7,操作系统是Ubuntu16 64位操作系统。

1.在/etc/security/limits.conf文件末尾加上如下内容

    List-1

* hard nofile 65535
* soft nofile 65535

2. 拷贝mysql.service,之后编辑

    List-2

sudo cp /lib/systemd/system/mysql.service /etc/systemd/system/
sudo vim /etc/systemd/system/mysql.service

    在/etc/systemd/system/mysql.service文件末尾加入如下List-3中的内容

    List-3

LimitNOFILE=65535
LimitMEMLOCK=65535

3.编辑/etc/mysql/my.cnf,加入List-4中的内容

    List-4

[mysqld]
max_connections=600

4.执行命令

    List-5

sudo systemctl daemon-reload

5.重启MySQL之后,查看performance_schema数据库,

    查看open_files_limit的值,这个值默认值是1024,我们可以看到这个值变为65535了,如下List-6所示。

    List-6

mysql> select * from global_variables where variable_name like "%open_file%";
+-------------------+----------------+
| VARIABLE_NAME     | VARIABLE_VALUE |
+-------------------+----------------+
| innodb_open_files | 2000           |
| open_files_limit  | 65535          |
+-------------------+----------------+
2 rows in set (0.00 sec)

    查看max_connections的值,如下List-7所示,max_connections的变为600了。

    List-7

mysql> select * from global_variables where variable_name like "%max_conn%";
+-----------------------+----------------+
| VARIABLE_NAME         | VARIABLE_VALUE |
+-----------------------+----------------+
| extra_max_connections | 1              |
| max_connect_errors    | 100            |
| max_connections       | 600            |
+-----------------------+----------------+
3 rows in set (0.00 sec)

 

Reference:

    1.https://www.digitalocean.com/community/questions/max_connections-will-not-change-in-ubuntu,途中遇到了一些问题,参考了这个链接的内容。

 

转载于:https://my.oschina.net/u/2518341/blog/1831276

你可能感兴趣的:(MySQL之修改max_connections)