MySQL 5.7 自增欄位相關引數說明
auto_increment_increment 和 auto_increment_offset引數用在主主複製中,用於控制AUTO_INCREMENT欄位的操作,在不同節點使用不同的生成規則,以避免生成的序列相同而產生衝突。這兩個引數可以分別設定全域性和會話的變數,每個引數的值的範圍是1~65535。將這兩個引數設定為0會導致實際上將這兩個引數的值設為1。
auto_increment_increment引數控制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.12 sec)
mysql> select @@auto_increment_increment;
+----------------------------+
| @@auto_increment_increment |
+----------------------------+
| 1 |
+----------------------------+
1 row in set (0.00 sec)
mysql> set @@auto_increment_increment=10;
Query OK, 0 rows affected (0.06 sec)
mysql> select @@auto_increment_increment;
+----------------------------+
| @@auto_increment_increment |
+----------------------------+
| 10 |
+----------------------------+
1 row in set (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.00 sec)
mysql> INSERT INTO autoinc1 VALUES(null),(null),(null);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SELECT col FROM autoinc1;
+-----+
| col |
+-----+
| 1 |
| 11 |
| 21 |
+-----+
3 rows in set (0.00 sec)
auto_increment_offset 引數決定AUTO_INCREMENT欄位的起始值
mysql> set @@auto_increment_offset=5;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE 'auto_inc%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 10 |
| auto_increment_offset | 5 |
+--------------------------+-------+
2 rows in set (0.00 sec)
mysql> CREATE TABLE autoinc2
-> (col int not null auto_increment primary key);
Query OK, 0 rows affected (0.64 sec)
mysql> INSERT INTO autoinc2 VALUES (null),(null),(null);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SELECT col FROM autoinc2;
+-----+
| col |
+-----+
| 5 |
| 15 |
| 25 |
+-----+
3 rows in set (0.00 sec)
auto_increment_increment引數控制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.12 sec)
mysql> select @@auto_increment_increment;
+----------------------------+
| @@auto_increment_increment |
+----------------------------+
| 1 |
+----------------------------+
1 row in set (0.00 sec)
mysql> set @@auto_increment_increment=10;
Query OK, 0 rows affected (0.06 sec)
mysql> select @@auto_increment_increment;
+----------------------------+
| @@auto_increment_increment |
+----------------------------+
| 10 |
+----------------------------+
1 row in set (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.00 sec)
mysql> INSERT INTO autoinc1 VALUES(null),(null),(null);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SELECT col FROM autoinc1;
+-----+
| col |
+-----+
| 1 |
| 11 |
| 21 |
+-----+
3 rows in set (0.00 sec)
auto_increment_offset 引數決定AUTO_INCREMENT欄位的起始值
mysql> set @@auto_increment_offset=5;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE 'auto_inc%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 10 |
| auto_increment_offset | 5 |
+--------------------------+-------+
2 rows in set (0.00 sec)
mysql> CREATE TABLE autoinc2
-> (col int not null auto_increment primary key);
Query OK, 0 rows affected (0.64 sec)
mysql> INSERT INTO autoinc2 VALUES (null),(null),(null);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SELECT col FROM autoinc2;
+-----+
| col |
+-----+
| 5 |
| 15 |
| 25 |
+-----+
3 rows in set (0.00 sec)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2098997/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql relay log相關引數說明MySql
- Mysql my.cnf部分引數說明MySql
- MySQL 5.7 mysqlpump 備份工具說明MySql
- mysql5.7 General tablespace使用說明MySql
- MySQL Galera cluster叢集常用引數說明MySql
- mysqldump引數說明MySql
- TOP引數說明
- MySQL 8 和 MySQL 5.7 在自增計數上的區別MySql
- 關於xtrabackup --slave-info引數的說明
- Oracle Table建立引數說明Oracle
- GoldenGate HANDLECOLLISIONS引數使用說明Go
- linux常用核心引數說明Linux
- 關於 navigator.mediaDevices.getUserMedia 的輸入引數說明dev
- 桌上型電腦電源相關引數說明
- mydumper和myloader引數使用說明
- Nginx的gzip配置引數說明Nginx
- LOB欄位相關概念(自動建立LOB索引段和重建索引方法)索引
- MySQL 5.7 新備份工具mysqlpump 使用說明 - 運維小結MySql運維
- /etc/sysctl.conf部分引數說明
- Azure Blob (三)引數設定說明
- 所有初始化引數說明(轉)
- pytest(10)-常用執行引數說明
- 關於MySQL中的8個 character_set 變數說明MySql變數
- MySQL:關於ICP特性的說明(未完)MySql
- JQuery Datatables Columns API 引數詳細說明jQueryAPI
- makefile中的一些引數說明
- MogDB 2.1.1 初始化引數概要說明
- 介紹tomcat Connector 引數優化說明Tomcat優化
- pt-online-schema-change使用引數說明
- 【cartographer_ros】七: 主要配置引數說明ROS
- MySQL效能相關引數MySql
- MySQL5.7統計資訊更新的相關引數解釋和測試MySql
- 隨筆:MySQL 查詢事務狀態欄位說明MySql
- jmeter如何實現引數自增JMeter
- ABAP-BITMAP的命令引數的使用說明
- C10-05-1-Nmap常用引數說明
- 資料泵的TRANSFORM引數說明及使用ORM
- MySQL5.7密碼欄位變更MySql密碼
- MySQL 連線相關引數MySql