Updating AUTO_INCREMENT value of all tables in a MySQL database

前端 未结 8 1680
旧巷少年郎
旧巷少年郎 2020-12-02 22:52

It is possbile set/reset the AUTO_INCREMENT value of a MySQL table via

ALTER TABLE some_table AUTO_INCREMENT = 1000

However I need

8条回答
  •  猫巷女王i
    2020-12-02 23:07

    set @db = 'your_db_name';
    
    SELECT concat('ALTER TABLE ', @db, '.', TABLE_NAME, ' AUTO_INCREMENT = 0;') 
    FROM information_schema.TABLES WHERE TABLE_SCHEMA = @db AND TABLE_TYPE = 'BASE TABLE'
    

    Then copy-paste and run the output you get.

提交回复
热议问题