我使用以下命令设置MySQL变量auto_increment_increment。
mysql -u root -p -e "SET GLOBAL auto_increment_increment = 10;"
所有这些都可以工作,直到我重新启动MySQL (使用sudo service mysql restart),然后变量才会恢复到默认状态。
在重新开始之前:
mysql> SHOW VARIABLES LIKE 'auto_%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 10 |
| auto_increment_offset | 1 |
+--------------------------+-------+
2 rows in set (0.00 sec)重新启动后:
mysql> SHOW VARIABLES LIKE 'auto_%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
+--------------------------+-------+
2 rows in set (0.00 sec)我怎样才能使这一变化永久化?
发布于 2015-10-13 12:23:51
您的命令只会临时更改行为。因此,在/etc/mysql/conf.d/中添加新的配置。避免/etc/mysql/my.cnf中的更改。为什么?请看我答案的结尾。
sudo nano /etc/mysql/conf.d/my.cnf再加上
[mysqld]
auto-increment-increment = 10重新加载配置或重新启动服务器。
取自标准my.cnf
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/发布于 2015-10-13 12:23:12
正如ssta所指出的,您可以使用配置文件。最好的位置可能是启动时使用的my.cnf文件。作出以下修改:
...
[mysqld]
auto_increment_increment = 10
...保存文件并重新启动服务器。
sudo service mysql restart这应该是可行的(我自己没有测试)。通过诅咒,你为什么想要这样的行为?
https://askubuntu.com/questions/684935
复制相似问题