I have an SQL dump of db1 that contains this line:
If I import that file into db2 with:
mysql -D db2 -uroot -p < /var/backups/db1.sql.gz
Is there the risk that db1 will be overriden?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
By reading the official documentation, I'll say that your guess is right, the dump script will override the DB1 database.
The USE db_name statement tells MySQL to use the db_name database as the default (current) database for subsequent statements. The database remains the default until the end of the session or another USE statement is issued.
The solution is the one proposed by Stuart, use a grep-like tool to find and replace "use db1" with "use db2" inside the dump file. Maybe even other references to db1 inside the dump script (procedures that use complete table names..). There are solutions for both Linux or Windows variants to edit that big text file.