tail -f findings.out

« Troubleshooting with MySQL binary logs

Advanced ordering of MySQL results »

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.

Share and Enjoy:
  • email
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Technorati
  • Netvibes

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

Possibly Related (no promises):

  1. mysql_secure_installation: A useful first step in securing a MySQL server
  2. Better access to MySQL create view statements
  3. Tune MySQL like a pro with MySQLTuner
  4. Advanced ordering of MySQL results
  5. Troubleshooting with MySQL binary logs

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

Tags: , ,
September 7, 2009 - 11:52 AM
2 comments »
  1. Advanced ordering of MySQL results | tail -f findings.out
  2. Better access to MySQL create view statements | tail -f findings.out
Leave a reply

Subscribe without commenting

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.