Created
January 5, 2018 19:29
-
-
Save AlexanderKharchenko/e3abffb8e8ec30b109f549405b9163b5 to your computer and use it in GitHub Desktop.
MYSQL: Truncate all table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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