I have a large database dump.sql file I am importing from the command line in linux. The .sql dump creates a database named "database_name". I want to import the database from this .sql file but I want to force it to a database with a different name, as the script currently overwrites "database_name" and "database_name" already exists and has data I can't overwrite.
Is the best option to find and replace within the .sql file? What is the best method for that since the file is 50mb. I can't simply file_get_contents() on that shiz? Can I?
Below are the lines I would have to replace in the .sql file:
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `database_name` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `database_name`;
When dumping the database with mysqldump
, use the option --no-create-db
. This will suspress the CREATE DATABASE
statement in your dump file.
Then restore the database withmysql -h <host> -u <user> -p <databaseName> < dump.sql
In this way you can restore your data in whatever database you like (But that database has to exist!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With