Problem
MySQL清空表中数据后,如何让自增ID从1开始?
Solution
清空表中数据时,使用truncate命令,而不用delete命令。
mysql> truncate test;
使用truncate命令的好处:
- 速度快:因为 trancate 命令是 DDL 语句,而 delete 语句是 DML 语句,因此 trancate 命令的执行非常快(当然 drawback 就是不能回滚,而 delete 语句可以)。
- 自增id会从 1 开始进算
关于 delete、drop、trancate 三种删除操作语句的区别,可访问【SQL】常用SQL语句。
Reference
- mysql清空表数据后如何让自增ID仍从1开始 - https://blog.csdn.net/bug_love/article/details/72626653
FEATURED TAGS
algorithm
algorithmproblem
architecturalpattern
architecture
aws
c#
cachesystem
codis
compile
concurrentcontrol
database
dataformat
datastructure
debug
design
designpattern
distributedsystem
django
docker
domain
engineering
freebsd
git
golang
grafana
hackintosh
hadoop
hardware
hexo
http
hugo
ios
iot
java
javaee
javascript
kafka
kubernetes
linux
linuxcommand
linuxio
lock
macos
markdown
microservices
mysql
nas
network
networkprogramming
nginx
node.js
npm
oop
openwrt
operatingsystem
padavan
performance
programming
prometheus
protobuf
python
redis
router
security
shell
software testing
spring
sql
systemdesign
truenas
ubuntu
vmware
vpn
windows
wmware
wordpress
xml
zookeeper