sql - Backing up a MySQL database and restoring it under another name - Stack Overflow
sql - Backing up a MySQL database and restoring it under another name - Stack Overflow
another name
Asked 13 years, 11 months ago Modified 9 years ago Viewed 9k times
I am trying to do some maintenance on MySQL database data and I created a dump file with the
backed up current database.
3
I want to restore all that data into another database called something like original_db_name_test
Share Improve this question Follow edited Dec 27, 2015 at 21:12 asked Jan 31, 2011 at 17:24
Brian Tompsett - 汤莱恩 Genadinik
5,875 72 61 133 18.6k 64 190 288
If you used mysqldump dbname , then your dump contains neither CREATE DATABASE nor USE
8
DATABASE .
Just create the database with the new name and feed the dump to mysql -D new_dbname .
If you used mysqldump --database dbname , then the dump contains CREATE DATABASE and USE
DATABASE statements.
yes after looking more closely at the file you are right. It was comments :) – Genadinik Jan 31, 2011 at
19:48
By the way, the current dump file has things like this for the tables: "ENGINE=MyISAM
AUTO_INCREMENT=92 DEFAULT CHARSET=latin1;" should I change the latin1 to utf-8 and that should do
the trick? Or that will only effect the tables? How do I change it for the entire database as well?
– Genadinik Jan 31, 2011 at 21:09
1 @Genadinik: unless you used explicit charset definitions for the individual columns, changing the table
DEFAULT CHARSET to UTF8 will create all the columns in the table as UTF8 and the data will go as
UTF8 . – Quassnoi Jan 31, 2011 at 21:11
2 Share Improve this answer Follow answered Jan 31, 2011 at 17:26
jschorr
3,044 1 19 21
I think this would not be right because the original dump file has the names of the original database name
and needs to have the names of the new database name. – Genadinik Jan 31, 2011 at 17:42
1 @jschorr because it depends on the parameters how your mysqldump was created. – sjas Jul 31, 2017 at
14:03
1. Create a new database (use the mysqladmin command line tool - "mysqladmin create [new
1
database name] ").
2. Edit the dump file to add a " USE [new database name]; " at the top. (There might be an
existing use statement that's commented out, so you can change this and un-comment it.)
3. Import the dump into the new table via " mysql -u <user name> -p < [dump file name] ".
Incidentally, when creating a dump via mysqldump, I'd be tempted to use the "--add-drop-table"
option, as this will cull any existing table with the same name prior to issuing the table creation
statement.
Share Improve this answer Follow answered Jan 31, 2011 at 17:30
John Parker
54.4k 11 131 130
you can use the 'MySQL Workbench' Application and do this with a nice gui
0 Share Improve this answer Follow answered Jan 31, 2011 at 17:33
bw_üezi
4,564 4 24 42