在MySQL中永久设置auto_increment_offset [英] Permanently setting auto_increment_offset in MySQL

查看:565
本文介绍了在MySQL中永久设置auto_increment_offset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以root身份运行命令:

I ran the command as root:

set @@auto_increment_offset = 2;

但是从其他连接看不到效果.为什么不?这是全球性的.

But the effect cannot be seen from other connections. Why not? It is global.

来自 http://dev.mysql.com /doc/refman/5.1/en/replication-options-master.html : 如果设置了任何一个变量的全局值,则其影响将持续到通过设置会话值更改或覆盖全局值,或者直到重新启动mysqld为止."

From http://dev.mysql.com/doc/refman/5.1/en/replication-options-master.html: "If the global value of either variable is set, its effects persist until the global value is changed or overridden by setting the session value, or until mysqld is restarted."

这似乎与我所看到的不一致.

That doesn't seem to agree with what I am seeing.

最后,我想知道是否有任何方法可以在不重新启动mysqld的情况下为所有客户端永久设置偏移量?

Ultimately, I would like to know if there any way to permanently set the offset for all clients without restarting mysqld?

推荐答案

根据MySQL

As per MySQL documentation you need to set values of auto_increment_offset for both GLOBAL and SESSION.

SET GLOBAL auto_increment_offset  = 2;
SET SESSION auto_increment_offset  = 2;

SHOW VARIABLES LIKE '%auto_increment_offset%';

如果设置了其中一个变量的全局值,则其影响将持续到通过设置会话值更改或覆盖全局值,或者直到重新启动mysqld为止.如果设置了本地值,则新值将影响会话期间当前用户在其中插入新行的所有表的AUTO_INCREMENT列,除非在该会话期间更改了值.

If the global value of either variable is set, its effects persist until the global value is changed or overridden by setting the session value, or until mysqld is restarted. If the local value is set, the new value affects AUTO_INCREMENT columns for all tables into which new rows are inserted by the current user for the duration of the session, unless the values are changed during that session.

这篇关于在MySQL中永久设置auto_increment_offset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆