Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysqldump question

Tags:

mysqldump

I am trying to dump a large database using mysqldump command. I would like to avoid 'use database' command in the generated sql file. This is because I want to create the same database with a different name. Since the sql file size is large I am unable to open the sql file and edit it.

I tried --no-create-db but still I am getting use command in the dump file

Please help.

like image 874
Pramod Sivadas Avatar asked Jan 11 '10 10:01

Pramod Sivadas


3 Answers

Maybe you used something like this:

mysqldump -u -p <other options> --database your_database > file.sql

I discovered that when you use --database, the script is generated with that 'use your_database' line. So, don't use that option and the line is gone:

mysql -u -p <other options> your_database > file.sql
like image 149
Felipe Avatar answered Nov 02 '22 07:11

Felipe


You should maybe post this on serverfault, but if you are on a linux box, you could consider sed (or perl/python scripts) to replace the name of the database, or remove the "use " line.

like image 27
Aif Avatar answered Nov 02 '22 06:11

Aif


The way to do this is to run mysqldump once for each database. They way I did it is mysqldump -u user -p --tables databasename. This dumps all the tables for a database and removes the USE database statement.

like image 1
spig Avatar answered Nov 02 '22 05:11

spig