Rapidly set up a MySQL database for testing

Sometimes you just want a database to run some queries against. Any reasonable set of tables with data pertaining to something not terribly complicated will do. Perhaps you have an urge to tease out the intricacies of correlated subqueries, or you need to test some complicated pattern matching functions. MySQL provides a database dump for such recreation, called “world”. The world database contains global population data from Statistics Finland. The data itself is several years old, but it works fine as general test fodder.

Since I normally only use it on my own machines for testing, I’ve found setting it up to be a fixed process. So I created this alias for such situations:

1
2
3
alias setup_world_db="wget -O /tmp/world.sql.gz http://downloads.mysql.com/docs/world.sql.gz && \
gunzip /tmp/world.sql.gz && mysql -u root -p -e 'create database if not exists world;' && \
mysql -u root -p world < /tmp/world.sql && rm /tmp/world.sql"

This pulls down the world database dump, unzips it, creates a DB to hold it, imports it, then removes the temporary files. You’ll be prompted twice for the password of the root MySQL user. You could also alter it to include the password if you are so inclined. Add the above alias line to ~/.bashrc, reload it, and you can have a test DB up and waiting within seconds anytime you want.

Post to Twitter Post to Delicious Post to Digg Post to Reddit

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

This entry was posted in MySQL and tagged , , . Bookmark the permalink.

3 Responses to Rapidly set up a MySQL database for testing

  1. Pingback: Advanced ordering of MySQL results | tail -f findings.out

  2. Pingback: Better access to MySQL create view statements | tail -f findings.out

  3. Pingback: Debugging bottlenecks with the MySQL Query Profiler | tail -f findings.out

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>