Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AlexanderKharchenko/e3abffb8e8ec30b109f549405b9163b5 to your computer and use it in GitHub Desktop.
Save AlexanderKharchenko/e3abffb8e8ec30b109f549405b9163b5 to your computer and use it in GitHub Desktop.
MYSQL: Truncate all table
mysql -Nse 'show tables' DATABASE -uMYUSER -pMYPASSWORD | while read table; do mysql -e "truncate table $table" DATABASE -uMYUSER -pMYPASSWORD ; done
# With FOREIGN_KEY_CHECKS
mysql -Nse 'show tables' DB_NAME -uMYSQL_USER -pMYSQL_PASSWORD | while read table; do mysql -e "SET FOREIGN_KEY_CHECKS=0; truncate table $table;SET FOREIGN_KEY_CHECKS=1;" DB_NAME -uMYSQL_USER -pMYSQL_PASSWORD ; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment