Skip to content

Instantly share code, notes, and snippets.

@ozscosta
Forked from abhinavlal/reset_autoincrement.sh
Last active November 6, 2020 18:58
Show Gist options
  • Save ozscosta/64575f578f2c3806cf84bebae93a43c0 to your computer and use it in GitHub Desktop.
Save ozscosta/64575f578f2c3806cf84bebae93a43c0 to your computer and use it in GitHub Desktop.
[Reset mysql autoincrement keys] Reset auto increment of all tables in a mysql database
mysql -Nsr -e "SELECT t.table_name FROM INFORMATION_SCHEMA.TABLES t WHERE t.table_schema = 'DB_NAME'" | xargs -I {} mysql DB_NAME -e "ALTER TABLE {} AUTO_INCREMENT = 1;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment