I have a large MySQL database, lets call it live_db
, which I want to replicate on the same machine to provide a test system to play around with (test_db
The mysql
command line client will accept a stream of SQL statements from standard input. You can therefore pipe the output of mysqldump
directly into mysql
on the command line. Doing this as a cron job will regularly overwrite your test data with updated live data:
mysql --user=username --password=passwd -e 'DROP DATABASE test_db;'
mysql --user=username --password=passwd -e 'CREATE DATABASE test_db;'
mysqldump --user=username --password=passwd live_db | mysql --user=username --password=passwd test_db
Note that since your data is large, it will take a long time.