Duplicate a MySQL Database without using mysqldump?


To duplicate a MySQL database, the syntax is as follows −

create table yourdatabaseName1.yourTableName1 select * from yourdatabaseName2.yourTableName2;

Let us first create a table −

mysql> use sample;
Database changed
mysql> create table DemoTable101
   -> (
   -> Id int,
   -> Name varchar(20)
   -> );
Query OK, 0 rows affected (1.45 sec)

Insert some records in the table using insert command−

mysql> insert into DemoTable101 values(101,'Sam');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable101 values(102,'Bob');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable101 values(103,'David');
Query OK, 1 row affected (0.11 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable101;

This will produce the following output −

+------+-------+
| Id   | Name  |
+------+-------+
|  101 | Sam   |
|  102 | Bob   |
|  103 | David |
+------+-------+
3 rows in set (0.00 sec)

Here is the query to duplicate a MySQL database −

mysql> create table web.DemoTable2 select * from sample.DemoTable101;
Query OK, 3 rows affected (0.71 sec)
Records: 3  Duplicates: 0  Warnings: 0

Display all records from the new table using select statement −

mysql> select * from web.DemoTable2;

This will produce the following output −

+------+-------+
| Id   | Name  |
+------+-------+
|  101 | Sam   |
|  102 | Bob   |
|  103 | David |
+------+-------+
3 rows in set (0.00 sec)

Updated on: 11-Dec-2019

564 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements