How to duplicate a MySQL database on the same server

前端 未结 6 1992
不知归路
不知归路 2021-01-31 01:51

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

6条回答
  •  野性不改
    2021-01-31 02:23

    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.

提交回复
热议问题