17.1.4.2 Replication Master Options and Variables

17.1.4.2 Replication Master Options and Variables 复制Master 选项和变量:

本节描述了server选项和系统变量 ,你可以使用在复制master server上。你可以指定选项在命令行或者选项文件,

你可以指定系统变量使用SET:

在master和每个slave上, 你必须使用server-id选项来建立一个唯一的复制ID.对于每个server,

你可以选择一个唯一的正数,每个ID 必须不同于其他ID

下面的系统变量用于控制复制master:

auto_increment_increment

System Variable Name auto_increment_increment
Variable Scope Global, Session
Dynamic Variable Yes
Permitted Values Type integer
Default 1
Min Value 1
Max Value 65535

auto_increment_increment and auto_increment_offset是用于主主复制,可以用于控制AUTO_INCREMENT 的操作。

两个变量都有global和session 值,每个值可以在1到65535之间,设置它们中的任何一个值为0会导致

值代替为1.

这两个变量影响AUTO_INCREMENT 列行为如下:

mysql> SHOW VARIABLES LIKE ‘auto_inc%’;
+————————–+——-+
| Variable_name | Value |
+————————–+——-+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
+————————–+——-+
2 rows in set (0.00 sec)

mysql> CREATE TABLE autoinc1
-> (col INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
Query OK, 0 rows affected (0.04 sec)

mysql> SET @@auto_increment_increment=10;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE ‘auto_inc%’;
+————————–+——-+
| Variable_name | Value |
+————————–+——-+
| auto_increment_increment | 10 |
| auto_increment_offset | 1 |
+————————–+——-+
2 rows in set (0.01 sec)

mysql> INSERT INTO autoinc1 VALUES (NULL), (NULL), (NULL), (NULL);
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> SELECT col FROM autoinc1;
+—–+
| col |
+—–+
| 1 |
| 11 |
| 21 |
| 31 |
+—–+
4 rows in set (0.00 sec)

原文地址:https://www.cnblogs.com/hzcya1995/p/13351321.html