mysql自动增长字段auto_increment 如何设置增长的长度,语句应该怎样写? 例如,我要auto_increment从10开始,增长长度为10,10,20,30,40,50。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以设置系统变量auto_increment_increment auto_increment_offset两个变量控制。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: 0mysql> SELECT col FROM autoinc1;+-----+| col |+-----+| 1 || 11 || 21 || 31 |+-----+4 rows in set (0.00 sec)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.06 sec)mysql> INSERT INTO autoinc2 VALUES (NULL), (NULL), (NULL), (NULL);Query OK, 4 rows affected (0.00 sec)Records: 4 Duplicates: 0 Warnings: 0mysql> SELECT col FROM autoinc2;+-----+| col |+-----+| 5 || 15 || 25 || 35 |+-----+4 rows in set (0.02 sec) 参考此贴:http://topic.csdn.net/u/20100318/10/ce55ca98-6b56-41a1-b7d0-7721f2c5441b.html mysql> show variables like 'auto_inc%';+--------------------------+-------+| Variable_name | Value |+--------------------------+-------+| auto_increment_increment | 10 || auto_increment_offset | 50 |+--------------------------+-------+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.05 sec)mysql> INSERT INTO autoinc2 VALUES (NULL), (NULL), (NULL), (NULL);Query OK, 4 rows affected (0.00 sec)Records: 4 Duplicates: 0 Warnings: 0mysql> SELECT col FROM autoinc2;+-----+| col |+-----+| 4 || 14 || 24 || 34 |+-----+4 rows in set (0.00 sec)怎么我的初始值是4而不是50的呢?MyISAM Mysql不能修改表数据 数据表中的索引id如何重置? 一条左连接SQL t1.role_id = t2.role.id ,但显示是却不等于的 WINDOWS 编译MYSQL 求教一个错误 频繁随机读取数据库性能优化问题 Mysqldump 多表联合条件数据导出如何设置 mysql登陆出现问题.请各位帮忙,急!~~~~ 寻找 mysql教程 MYsql中如何计算某列除以该列的总和 求一种特殊多表连接查询sql语句 求一条sql语句
auto_increment_increment
auto_increment_offset两个变量控制。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: 0mysql> SELECT col FROM autoinc1;
+-----+
| col |
+-----+
| 1 |
| 11 |
| 21 |
| 31 |
+-----+
4 rows in set (0.00 sec)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.06 sec)mysql> INSERT INTO autoinc2 VALUES (NULL), (NULL), (NULL), (NULL);
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0mysql> SELECT col FROM autoinc2;
+-----+
| col |
+-----+
| 5 |
| 15 |
| 25 |
| 35 |
+-----+
4 rows in set (0.02 sec)
http://topic.csdn.net/u/20100318/10/ce55ca98-6b56-41a1-b7d0-7721f2c5441b.html
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 10 |
| auto_increment_offset | 50 |
+--------------------------+-------+
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.05 sec)mysql> INSERT INTO autoinc2 VALUES (NULL), (NULL), (NULL), (NULL);
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0mysql> SELECT col FROM autoinc2;
+-----+
| col |
+-----+
| 4 |
| 14 |
| 24 |
| 34 |
+-----+
4 rows in set (0.00 sec)
怎么我的初始值是4而不是50的呢?MyISAM