MySQL Drop All Tables Shell Script Utility

Posted on in Categories MySQL last updated November 13, 2008

8 comment

  1. Really great script. I grabbed a few pieces of it for one I’m working on. Saved me a ton of time. I made one tweak to the part where you check if the tables exist.

    # make sure tables exits
    if [ ! $MYSQLTABLES ]
    then
    echo "Error - No table found in $MDB database!"
    exit 3
    fi

  2. good script, add internal mysql options:

    • – B: Print results using tab as the column separator, with each row on a new line. With this option, mysql does not use the history file.
    • -N: Do not write column names in results.
  3. I have one problem with this script.
    It does not take foreign keys into account. It will try to delete tables that have dependencies to other tables and this will throw a error.
    I your script would build a dependencies tree and delete top-down it would be perfect ;)

  4. why wouldn’t you just drop the database if you were going to drop all of the tables? in mysql even if you drop the db it keeps user and host info, so you could just recreate it.

    drop database $db; create database $db;

Leave a Comment