Skip to content

Instantly share code, notes, and snippets.

@pataiji
Created May 14, 2014 09:55
Show Gist options
  • Select an option

  • Save pataiji/350ebfe8ad6ad98efe0e to your computer and use it in GitHub Desktop.

Select an option

Save pataiji/350ebfe8ad6ad98efe0e to your computer and use it in GitHub Desktop.
テーブルの一括削除のメモ
#!/bin/bash
function db_truncate_tables {
database=$1
/usr/local/bin/mysql -u root -D $database -e 'show tables;' | \
cut -f 2 | grep -v Tables_in_ | \
xargs -I "@@" mysql -u root -D $database -e "set foreign_key_checks=0; DROP TABLE \`@@\`; set foreign_key_checks = 1;"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment