关于mysql:MysqlHow-to-Increase-Max-Connections-in-MySQL

15次阅读

共计 1987 个字符,预计需要花费 5 分钟才能阅读完成。

原文

How to Increase Max Connections in MySQL

引言

有时候连贯 Mysql 时候咱们会遇到“Too many connections”这样的报错,当然更多可能是在生产过程中碰到这样的问题,默认状况下 Mysql 的整体服务器连接数设置过低。

Sometimes MySQL server may give“Too many connections”error message when you try to connect to a MySQL database. Here’s how to increase max connections in MySQL to fix this problem.

Too many connections 的影响

这意味着所有可用的连贯曾经被各种客户端应用,你的 MySQL 服务器不能关上任何新的连贯,直到任何现有的连贯被敞开。

By default, MySQL 5.5+ can handle up to 151 connections. This number is stored in server variable called _max_connections_. You can update max_connections variable to increase maximum supported connections in MySQL, provided your server has enough RAM to support the increased connections.

max_connections 默认值

By default, MySQL 5.5+ can handle up to 151 connections. This number is stored in server variable called _max_connections_. You can update max_connections variable to increase maximum supported connections in MySQL, provided your server has enough RAM to support the increased connections.

在 Mysql5.5+ 的版本中,这个值只有 151,咱们能够通过 show variables like "max_connections"; 查看本人的 Mysql 服务器最大连接数。依据以后的机器配置和理论状况,咱们能够拉大这个参数。

mysql> show variables like "max_connections";
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151 |
+-----------------+-------+
1 row in set (0.01 sec)

如何扩充 max_connections 这个值?(docker 中的 Mysql 为例)

上面是根底步骤。

0. 如何查看?

首先咱们须要理解如何查看以后的最大连接数。

show variables like "max_connections";

navicat 能够在 命令行模式 下查看查看连接数(这里为集体试验批改后后果):

有两种办法来减少 MySQL 连贯。上面是通过 MySQL 命令行工具更新最大连接数为 200 的命令,无需重新启动。

1. 长期批改:命令

通过 Mysql 连贯到客户端,能够应用上面的命令批改最大连接数:

mysql> set global max_connections = 200;

然而须要留神这种批改形式 一旦重启就会生效,所以这个命令通常是在呈现相似的生产事变的时候救急应用。

如果想要永恒失效,须要批改 mysql 的相干配置文件。

2. 永恒失效:系统配置批改

要永恒失效须要批改系统配置,

sudo vi /etc/my.cnf

须要留神依据 Linux 发行版和装置类型不同,my.cnf 文件可能位于以下任何地位。如果是 docker,则 my.cnf 位于自定义映射的地位

  • /etc/my.cnf
  • /etc/mysql/my.cnf
  • $MYSQL_HOME/my.cnf
  • ~/.my.cnf

留神这个参数要配置到 [mysqld] 上面。

[mysqld]
max_connections = 10024

最初只须要重启 Mysql 服务即可。

重启 Mysql

集体搭建的 Docker 只须要重启镜像即可,较为不便。

[root@localhost conf]# docker restart 58f

docker 的 ID 反对含糊匹配。也能够自定义 name 之后进行重启。

写在最初

心愿上述教程能帮忙你理解如何减少 MySQL 的最大连接数。

Hopefully, the above tutorial will help you increase max connections in MySQL.

正文完
 0