i2tutorials

MySQL – Copy Database

MySQL – Copy Database

 

Databases are applications that store organized collections of records that can be accessed and managed by users. The data is organized into tables, rows, columns, and indexes so that the relevant information can be found quickly.

The MySQL copy or clone database function allows us to create a duplicate copy of an existing database, including the table structure, indexes, constraints, default values, etc. Making a duplicate copy of an original database into a new database is very useful if the original database is lost or fails accidentally. The most common purpose for making a duplicate copy of the database is to make a backup of the data. Additionally, it is useful when planning major modifications to the original database’s structure.

The steps we need to follow in order to copy a database from one database to another are as follows:

  1. In order to create a new database, you will need to use the CREATE DATABASE statement.
  2. The second step is to store the data in an SQL file. In this case, we can name this file whatever we like, as long as it ends with a .sql extension.
  3. As a third step, you must export all the database objects as well as their data to be copied using the mysqldump tool, and then import the file into your new database.

The following steps will be used in the demonstration to copy the employees database to the employees_copy database using the following steps:

The first thing we need to do is open the MySQL console and write down the password we set during installation. The next step is to create a duplicate database of employees based on the following command:

#start
CREATE DATABASE employees_copy;
#end

The next step is to verify the database information using the SHOW DATABASES statement:

#start
SHOW DATABASES;
#end

d1

Step 1:

 You will need to connect to the database you want to back up by clicking on it under the MySQL Connections tab.

The “Administration” window will appear as shown in the following image.

Step 2:

There is a data export option under the “Management” tab on the left sidebar of the screen.

Step 3

Step 4

Step 5

Step 6

There is a data import option under the “Management” tab on the left sidebar of the screen.

Step 7 

Step 8

 

Exit mobile version