MariaDB - 无法通过my.cnf设置max_connections

时间:2016-05-04 07:36:33

标签: mysql mariadb

我很难在/etc/my.cnf中设置max_connections参数,但MariaDB似乎没有从文件中读取参数。

我的/etc/my.cnf文件:

[mysqld]
#skip-grant-tables
datadir=/data/mysql
socket=/data/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# network
connect_timeout = 60
wait_timeout = 28800
max_connections = 100000
max_allowed_packet = 64M
max_connect_errors = 1000

# limits
tmp_table_size = 512M
max_heap_table_size = 256M
table_cache = 512

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

[client]
port = 3306
socket= /data/mysql/mysql.sock

但是当我检查MariaDB中的变量时,它会显示默认值:

MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 214   |
+-----------------+-------+
1 row in set (0.00 sec)

但是,my.cnf中的其他参数是正确的:

MariaDB [(none)]> show variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout  | 28800 |
+---------------+-------+
1 row in set (0.00 sec)

MariaDB [(none)]> show variables like 'max_allowed_packet';
+--------------------+----------+
| Variable_name      | Value    |
+--------------------+----------+
| max_allowed_packet | 67108864 |
+--------------------+----------+
1 row in set (0.00 sec)


MariaDB [(none)]> show variables like 'max_connect_errors';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| max_connect_errors | 1000  |
+--------------------+-------+
1 row in set (0.00 sec)

MariaDB [(none)]> show variables like 'connect_timeout';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| connect_timeout | 60    |
+-----------------+-------+
1 row in set (0.00 sec)

我可以从mysql命令行设置此变量,但是当我重新启动服务时它会重置:

MariaDB [(none)]> set global max_connections := 10000;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 10000 |
+-----------------+-------+
1 row in set (0.00 sec)

操作系统:RHEL 7

MariaDB版本:mariadb-server-5.5.47-1.el7_2.x86_64

见这里:https://dba.stackexchange.com/questions/137487/mariadb-cannot-set-max-connections-and-wait-timeout-through-my-cnf

4 个答案:

答案 0 :(得分:3)

我认为解决方案就在这里。增加打开文件限制。

https://dba.stackexchange.com/questions/12061/mysql-auto-adjusting-max-connections-values

答案 1 :(得分:1)

我在ubuntu服务器上遇到同样的问题。我已更改此文件/etc/mysql/my.cnf

max_connections = 1000

然后执行查询。 你正在改变错误的文件。

答案 2 :(得分:0)

在具有Maria DB的Ubuntu服务器中,在 /etc/mysql/mariadb.conf.d/50-server.cnf

中输入参数 max connections

重新启动服务以使更改生效。

systemctl restart mariadb

答案 3 :(得分:0)

是的 - 我知道 - 死灵法术 - 但没有更好的答案,所以这里是:

我自己被这个问题困扰了很长时间。然而,就在今天,我意识到有时配置文件中的注释会有所帮助。即,在 2. 中找到的以下行号 /etc/mysql/mariadb.cnf 中标识的目录:

# The MariaDB/MySQL tools read configuration files in the following order:
# 0. "/etc/mysql/my.cnf" symlinks to this file, reason why all the rest is read.
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.

因此,您需要将全局选项添加到名为 [mysqld] 的部分到一个文件中,例如 /etc/mysql/conf.d/myoptions.cnf

重新启动 MariaDB,您的设置将保持不变。

相关问题