Drop all tables in MySQL (part 2)

Submitted by Jochus on Mon, 17/05/2010 - 11:22 | Posted in: Database

Funny, last week I made this blogpost. Today, I had to do the same, but for a MySQL 5.x database.

As I didn't wanted to start a MySQL client, I wrote a small bash command to perform the operation for me:

<a href="mailto:jochen@baileys">jochen@baileys</a> $ mysqldump -u ##USERNAME## -p##PASSWORD## --add-drop-table --no-data ##DATABASE## | grep ^DROP | mysql -u ##USERNAME## -p##PASSWORD## ##DATABASE##

What does this command do?

  • dump your database to the STDOUTPUT, with ADD-DROP lines, but don't export data, only DDL
  • grep all lines which start with the "DROP" statement
  • pump these lines to your mysql client (which I start on command line)

Add new comment

The content of this field is kept private and will not be shown publicly.

Full HTML

  • Lines and paragraphs break automatically.
  • You can caption images (data-caption="Text"), but also videos, blockquotes, and so on.
  • Web page addresses and email addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <cpp>, <css>, <html5>, <java>, <javascript>, <php>, <sql>, <xml>. The supported tag styles are: <foo>, [foo].
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.