Colin Robinson

Quickly reload a database

I’m mostly posting this to copy/paste when I forget, but it’s useful information nonetheless so lets have at it.

  1. Delete the database
  2. Create a new database
  3. Import SQL file into the new database

Assume the mysql user/pass combo is colin/mypassword and the database is called db123.

mysqladmin -u colin -pmypassword drop db123;
mysqladmin -u colin -pmypassword create db123;
mysql -u colin -pmypassword db123 < db123_backup.sql

If you’re working on something and you need to reload your database a lot, you can put all the commands on one line (still with semicolons of course) and add -f to the first command to skip the delete check.

Very very basic stuff here, but I’m sure the 3min it took me to write this saved someone else more time than that.

One Response to “Quickly reload a database”

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.