Mysql method to set auto-increasing id: First create the database, select Create Table; then when designing the table fields, the last parameter AI of the id column is auto-increasing, just check it.
![How to set auto-increment id in mysql](https://img.php.cn/upload/article/202012/15/2020121514154518763.jpg)
The operating environment of this tutorial: windows7 system, mysql8.0.22, thinkpad t480 computer.
Related free learning recommendations: mysql database(Video)
##mysql Method to set auto-increment id:
1. Open MySQL Workbench, create a database, right-click Tables, and select Create Table
![1608013271753246.png How to set auto-increment id in mysql](https://img.php.cn/upload/image/743/397/857/1608013271753246.png)
2 . When designing table fields, the last parameter AI (Auto Increment) of the id column is auto-increment. Just check it. It should be noted that it must be defined as INT type and must be set as an index. In this example, id is set as the primary key and defaults to the primary key index.
![1608013275311631.png How to set auto-increment id in mysql](https://img.php.cn/upload/image/793/678/752/1608013275311631.png)
3. Execute Apply to create the table
![1608013279272720.png How to set auto-increment id in mysql](https://img.php.cn/upload/image/228/774/829/1608013279272720.png)
4. You can also create the table through SQL commands
![1608013285681591.png How to set auto-increment id in mysql](https://img.php.cn/upload/image/761/195/948/1608013285681591.png)
5. After the creation is successful, we insert a record and observe that the id column automatically grows to 1
![1608013289847648.png How to set auto-increment id in mysql](https://img.php.cn/upload/image/431/842/352/1608013289847648.png)
6. In mysql, we can manually assign values to self-increasing columns
![1608013298866345.png How to set auto-increment id in mysql](https://img.php.cn/upload/image/743/647/232/1608013298866345.png)
7. After assignment, the records that will self-increase in the future will be based on our assignment. 1, here should be the maximum Based on the value 1
![1608013304644892.png How to set auto-increment id in mysql](https://img.php.cn/upload/image/569/276/552/1608013304644892.png)
8. If you want to clear the table and start assigning values again, you need to execute the truncate command
![1608013308327171.png How to set auto-increment id in mysql](https://img.php.cn/upload/image/741/140/861/1608013308327171.png)
Related free learning recommendations: php programming (video)
The above is the detailed content of How to set auto-increment id in mysql. For more information, please follow other related articles on the PHP Chinese website!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn