How to duplicate a MYSQL database?

Asked

Viewed 7,297 times

4

Is there any way to duplicate a database on MYSQL by the execution of any query?

I can copy a table with this code:

CREATE TABLE table_2 AS SELECT * FROM table_1

But how to copy replicate a particular database (on the same host)?

2 answers

5


  • 1

    I like this technique, I’m going to adopt!

5

I usually do this outside of phpMyAdmin, using mysqldump in the shell. First you dump the current base:

mysqldump -R --user=usuario --password=senha nomedabase > arquivo.sql

The -R is to include procedures and functions in the dump. Then you create an empty base (can be by Myadmin or any client), and import the dump back:

mysql --user=usuario --password=senha basedestino < arquivo.sql
  • That operator < works the same way as cat of terminal?

  • The cat plays content for standard output. O < reads the file to default input.

  • Great example +1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.