Skip to content

Instantly share code, notes, and snippets.

@cmerrick
Created October 20, 2015 02:50
Show Gist options
  • 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