Login

Drop all tables in MySQL database

Author:
mpasternacki
Posted:
January 28, 2010
Language:
SQL
Version:
Not specified
Tags:
sql mysql maintenance
Score:
1 (after 1 ratings)

Drops all tables in MySQL table (either managed by Django or not). Useful when resetting the database with no CREATE DATABASE privileges. MySQL-only.

1
2
3
4
5
echo 'show tables;' \
    | python manage.py dbshell \
    | sed -n 2,\$p \
    | awk 'BEGIN {print "set foreign_key_checks=0;"} { print "drop table `" $1 "`;"}' \
    | python manage.py dbshell

More like this

  1. Custom SQL via subquery by drg006 8 years ago
  2. oneliner to delete SQLite tables by kifkif 5 years, 7 months ago
  3. Creating MySQL Alter table commands for Foreign Keys by vidyanand 6 years, 11 months ago
  4. Clean up expired django.contrib.session's in a huge MySQL InnoDB table by patsplat 6 years, 4 months ago
  5. fast table flush without raw SQL by dsblank 5 years, 5 months ago

Comments

Please login first before commenting.