mysql修改數據表自增步長


可以修改系統變量 auto_increment_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> 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    |     //已設置為10
| auto_increment_offset    | 1     |
+--------------------------+-------+
2 rows in set (0.01 sec)

數據表自增將以10為間隔自增

如果以上方法還不生效,或者重啟mysql后,又變回來了。那肯定是在my.cnf里面設置了全局變量。這個必須到配置文件里面去修改了;這種修改永久有效。而且無法通過上面的操作再次被修改。

用vi編輯器打開配置文件,默認位置
#vi /etc/my.cnf

找到 auto_increment_increment 變量設置的地方;VI里面可以用 "/auto_increment_increment" 找到。

找到后設置
auto_increment_increment=1;即可

其他全局變量也可在此配置文件里面永久設置好。
配置文件修改好后,要重啟mysql服務才會生效。
#/etc/init.d/mysql restart


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM