Mysql – Copying a database for testing in a safe way

backupinnodbMySQLmysqldump

For testing purposes I have to create a copy of a production MySQL database that cannot be touched.

These are the steps I would follow:

  1. Create a reduced size database backup:

    mysqldump prodDB --single-transaction --where="true limit 20" > test.sql

  2. Create a new test database: testDB

  3. Load the dump file in the new test database:

    mysql testDB < test.sql

Is this procedure correct?
Can I be sure that the original database will not be modified whatsoever?

Thank you!

System: MySQL 5.1 with InnoDB

Best Answer

Is this procedure correct ?

If you have no foreign key constraints, then yes this is correct.

If you have foreign key constraints, some data may be inaccessible. You would have to fix it.

Can I be sure that the original database will not be modified whatsoever?

After the mysqldump do the following:

grep -c "DROP DATABASE" test.sql

If you get back 0, then yes the original database will not be modified whatsoever