• 0

Duplicate database


Question

Hi,

I have a database which is functioning for a forum. I am now working on a second version of that forum so I would like to have my current database as test database and therefore take a copy.

Currently I found this script:


mysqladmin create new_DB_name -u DB_user --password=DB_pass && \
mysqldump -u DB_user --password=DB_pass DB_name | mysql -u DB_user --password=DB_pass -h DB_host new_DB_name
[/CODE]

But before I take action I would like to know where I have to place this code. And secondly what data I have to replace in above text if my current setup is:

Current database name: forum

Current database user: forumuser

Current user pass: test001

New database name: backup

New database user: backupuser

New user pass: eggplant001

Thanks in advance! I do not want to take chances with my current database.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

This script is run on command line. mysqladmin, mysqldump, and mysql are programs, this script runs them both and passes proper arguments to them.

This:

mysqladmin create new_DB_name -u DB_user --password=DB_pass
[/CODE]

[/color]

[color=#000000]Logs into a mysql server and creates a new database called new_DB_name. It looks like you already have a database created on your new server (backup) so you shouldn't need this.[/color]

[color=#000000]The ?&&? combines two commands the[/color]

[color=#000000]

[CODE]mysqladmin create new_DB_name -u DB_user --password=DB_pass
[/CODE]

[/color]

[color=#000000]and the[/color]

[color=#000000]

[CODE]mysqldump -u DB_user --password=DB_pass DB_name | mysql -u DB_user --password=DB_pass -h DB_host new_DB_name
[/CODE]

[/color]

[color=#000000]Because this input is long the backslash(?\?) continues the command onto the next line.[/color]

[color=#000000]Because you already have a database, you only need to run:[/color]

[color=#000000]

[CODE]
mysqldump -u DB_user --password=DB_pass DB_name | mysql -u DB_user --password=DB_pass -h DB_host new_DB_name
[/CODE]

[/color]

[color=#000000]

[CODE]
mysqldump -u DB_user --password=DB_pass DB_name
[/CODE]

[/color]

[color=#000000]Logs into your original database and dumps it. The pipe(?|?) character redirects that output to[/color]

[color=#000000]

[CODE]
mysql -u DB_user --password=DB_pass -h DB_host new_DB_name
[/CODE]

[/color]

[color=#000000]Which logs into your new database and will (I presume) add the dump.[/color]

[color=#000000]So, try:[/color]

[color=#000000]

[CODE]
mysqldump -u forumuser --password=test001 forum | mysql -u backupuser --password=eggplant001 -h DB_host backup
[/CODE]

[/color]

[color=#000000]You need to change ?DB_host? to your new database host, and I?m not sure how mysqldump is going to contact your server because there?s place to input your host(you?ll probably need to add a ?h flag and provide the host for your old database).[/color]

Link to comment
Share on other sites

This topic is now closed to further replies.