How To Copy a MySQL Database

Bạn đang xem: How To Copy a MySQL Database Tại DongnaiArt

Cùng xem How To Copy a MySQL Database trên youtube.

Summary: this tutorial shows you how to copy a MySQL database on the same server and from a server to another.

Copy a MySQL database on the same server

Copy MySQL Database

To copy a MySQL database, you need to follow these steps:

  1. First, create a new database using CREATE DATABASE statement.
  2. Second, export all the database objects and data of the database from which you want to copy using mysqldump tool.
  3. Third, import the SQL dump file into the new database.

For the demonstration, we will copy the classicmodels database to classicmodels_backup database.

Step 1. Create the classmodels_backup database:

First, log in to MySQL database server:

>mysql -u root -p Enter password: ********** Code language: SQL (Structured Query Language) (sql)

Then, use CREATE DATABASE statement as follows:

> CREATE DATABASE classicmodels_backup; Code language: SQL (Structured Query Language) (sql)

Third, use SHOW DATABASES command to verify:

> SHOW DATABASES Code language: SQL (Structured Query Language) (sql)

MySQL database server returns the following output:

Xem Thêm : Top 10 cổng game uy tín nhất tại Bầu cua online C.A Cerro 

+-+ | Database | +-+ | classicmodels | | classicmodels_backup | | information_schema | | mysql | | performance_schema | | sys | +-+ 6 rows in set (0.00 sec) Code language: SQL (Structured Query Language) (sql)

As you see, we have created the classicmodels_backup database successfully.

Step 2. Dump database objects and data into SQL file using the mysqldump tool.

Suppose, you want to dump the database objects and data of the classicmodels database into an SQL file located at D:db folder, here is the command:

>mysqldump -u root -p classicmodels > d:dbDongnaiart Enter password: ********** Code language: SQL (Structured Query Language) (sql)

Basically, this command instructs mysqldump to log in to the MySQL server using the root user account with a password and exports the database objects and data of the classicmodels database to d:dbclassicmodels.sql. Note that the operator (>) means exporting.

Step 3. Import the d:dbDongnaiart file into classicmodels_backup database.

>mysql -u root -p classicmodels_backup < d:dbDongnaiart Enter password: ********** Code language: SQL (Structured Query Language) (sql)

Note that the operator ( <) means importing.

To verify the import, you can perform a quick check by using the SHOW TABLES command.

> SHOW TABLES FROM classicmodels_backup; Code language: SQL (Structured Query Language) (sql)

It returned the following output:

Xem Thêm : 100+ Bài văn mẫu Nghị luận Văn Học lớp 8 hay nhất 2020 – Elib.vn

+-+ | Tables_in_classicmodels_backup | +-+ | customers | | employees | | offices | | orderdetails | | orders | | payments | | productlines | | products | +-+ 8 rows in set (0.01 sec) Code language: SQL (Structured Query Language) (sql)

As you see, we have successfully copied all the objects and data from the classicmodels database to classicmodels_backup database.

Copy a MySQL database from a server to another

To copy a MySQL database from a server to another, you use the following steps:

  1. Export the database on the source server to a SQL dump file.
  2. Copy the SQL dump file to the destination server
  3. Import the SQL dump file to the destination server

Let’s take a look at how to copy the classicmodels database from a server to another.

First, export the classicmodels database to db.sql file.

>mysqldump -u root -p -databases classicmodels > d:dbdb.sql Enter password: ********** Code language: SQL (Structured Query Language) (sql)

Note that -database option allows mysqldump to include both CREATE DATABASE and USE statements in the SQL dump file. These statements will create the classicmodels database in the destination server and make the new database as the default database for loading the data.

In short, the following statements are included at the beginning of the SQL dump file when we use -database option.

CREATE DATABASE `classicmodels`. USE `classicmodels`; Code language: SQL (Structured Query Language) (sql)

Third, import the db.sql file to the database server with the assumption that the db.sql file was copied to c:tmp folder.

>mysql -u root -p classicmodels < c:tmpdb.sql Code language: SQL (Structured Query Language) (sql)

In this tutorial, you have learned step by step how to copy a MySQL database on the same server and copy database from a server to another.

Nguồn: https://dongnaiart.edu.vn
Danh mục: Tin tức

Lời kết: Trên đây là bài viết How To Copy a MySQL Database. Hy vọng với bài viết này bạn có thể giúp ích cho bạn trong cuộc sống, hãy cùng đọc và theo dõi những bài viết hay của chúng tôi hàng ngày trên website: Dongnaiart.edu.vn

Related Posts

Top 5 nhà cái giao dịch rút tiền nhanh chóng và hiệu quả

Top 5 nhà cái giao dịch rút tiền nhanh chóng và hiệu quả

Trong thế giới cá cược trực tuyến, việc chọn lựa nhà cái có dịch vụ giao dịch rút tiền nhanh chóng và hiệu quả là một yếu…

Bíp kíp bắt kèo đá gà trực tiếp uy tín, đơn giản cho kê thủ

Bíp kíp bắt kèo đá gà trực tiếp uy tín, đơn giản cho kê thủ

Các trang cá cược ngày nay đã phát triển một loạt các kèo đá gà trực tiếp, mang lại sự đa dạng và cơ hội kiếm tiền…

Cách lựa chọn nhà cái trực tuyến uy tín và chất lượng

Cách lựa chọn nhà cái trực tuyến uy tín và chất lượng

Khi quyết định tham gia cá cược trực tuyến, việc lựa chọn một nhà cái uy tín và chất lượng là điều vô cùng quan trọng. Trên…

Cược Đá Gà HB88 Và Những Ưu Đãi Ngập Tràn Tại Nhà Cái 

Cược Đá Gà HB88 Và Những Ưu Đãi Ngập Tràn Tại Nhà Cái 

Sảnh đá gà HB88 được xem là một trong những điểm đến cá cược hấp dẫn, mang đến những trận đấu đầy kịch tính, căng thẳng. Trong…

Roulette là gì? Kinh nghiệm chơi Roulette luôn thắng từ cao thủ

Roulette là gì? Kinh nghiệm chơi Roulette luôn thắng từ cao thủ

Roulette là gì? Roulette là một trò chơi sòng bạc phổ biến được chơi trên một bàn quay có chứa một bánh xe quay và một bảng…

Giải thích kèo chấp 1.5 – Các mẹo chơi hiệu quả 

Giải thích kèo chấp 1.5 – Các mẹo chơi hiệu quả 

Bóng đá được mệnh môn thể thao vua, là niềm đam mê của không ít người hâm mộ trên toàn thế giới. Kèo chấp 1.5 trong bóng…