Skip to content

Instantly share code, notes, and snippets.

@cmerrick
Created October 20, 2015 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmerrick/63dfb45ddf9708e0010b to your computer and use it in GitHub Desktop.
Save cmerrick/63dfb45ddf9708e0010b to your computer and use it in GitHub Desktop.
Truncate all tables in a MySQL DB
#!/bin/bash
DB=$1
mysql -Ne "SELECT TABLE_NAME FROM TABLES WHERE TABLE_SCHEMA='$1'" INFORMATION_SCHEMA | while read TABLE; do
mysql -Ne "TRUNCATE \`$TABLE\`" $DB
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment