0% found this document useful (0 votes)
13 views

sql - Backing up a MySQL database and restoring it under another name - Stack Overflow

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

sql - Backing up a MySQL database and restoring it under another name - Stack Overflow

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Backing up a MySQL database and restoring it under

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

Is there a command for that?

mysql sql database

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

4 Answers Sorted by: Highest score (default)

This depends on how you invoked mysqldump

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.

You need to comment them out or replace with new_dbname .

By clicking “Accept all


Share Improve thiscookies”,
answer you agree Stack Exchange
Follow answered Jan 31, 2011 at 17:29
can store cookies on your device and disclose information in
Quassnoi
accordance with our Cookie Policy.
425k 93 626 619

Accept all cookies Necessary cookies only


Hmmm, I did use the mysqldump command and while I do not have things like "create databasename" in
my dump, I do have references to the database name in the dump. Here is an example: "Host: localhost
Database: hiking" ....So that
Customize probably means that I have to rename the references to my original dbname to
settings
the new one. Thanks :) – Genadinik Jan 31, 2011 at 17:48
@Genadinik: the things you are referring to seem to be comments. – Quassnoi Jan 31, 2011 at 17:50

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

mysql -u usernamehere -p original_db_name_test < yourdumpfilehere.sql

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

By clicking “Accept all cookies”, you agree Stack Exchange


can store cookies on your device and disclose information in
accordance with our Cookie Policy.
If you used mysqldump to create the dump file, simply:

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

By clicking “Accept all cookies”, you agree Stack Exchange


can store cookies on your device and disclose information in
accordance with our Cookie Policy.

You might also like