Bang hộiTiền mặt: 0 Xu Trò chơiHộp quà giáng sinhThứ Tư, 01:51:59 - 08/05/2024
Chia sẻ kiến thức sử dụng VPS (máy chủ ảo) - Server (máy chủ riêng)

Các điều hành viên: Mod, SMod, Admin

How To Backup And Restore MySQL On Linux

How To Backup And Restore MySQL On Linux

#1 » Gửi bài gửi bởi nghiatichxanh1992 » 16/09/2018 22:38 » @503430

This article shows you several practical examples on how to perform various backup operations of MySQL databases using mysqldump command and also we will see how to restore them with the help of mysql and mysqlimport command in Linux.

mysqldump is a command-line client program, it is used to dump local or remote MySQL database or collection of databases for backup into a single flat file.

How To Backup And Restore MySQL On Linux

We assume that you already have MySQL installed on Linux system with administrative privileges and we assume that you already have a small amount of knowledge on MySQL. If you don’t have MySQL installed or don’t have any exposure to MySQL then read our articles below.


How to Backup MySQL Database?

To take a backup of MySQL database or databases, the database must exist in the database server and you must have access to it. The format of the command would be.

Mã: Chọn tất cả
mysqldump -u [username] –p[password] [database_name] > [dump_file.sql]


The parameters of the said command as follows:
[username] : A valid MySQL username.
[password] : A valid MySQL password for the user.
[database_name] : A valid Database name you want to take backup.
[dump_file.sql] : The name of backup dump file you want to generate.


How to Backup a Single MySQL Database?

To take a backup of single database, use the command as follows. The command will dump database [rsyslog] structure with data on to a single dump file called rsyslog.sql.

Mã: Chọn tất cả
mysqldump -u root -ptecmint rsyslog > rsyslog.sql



How to Backup Multiple MySQL Databases?

If you want to take backup of multiple databases, run the following command. The following example command takes a backup of databases [rsyslog, syslog] structure and data in to a single file called rsyslog_syslog.sql.

Mã: Chọn tất cả
mysqldump -u root -ptecmint --databases rsyslog syslog > rsyslog_syslog.sql



How to Backup All MySQL Databases?

If you want to take backup of all databases, then use the following command with option –all-database. The following command takes the backup of all databases with their structure and data into a file called all-databases.sql.

Mã: Chọn tất cả
mysqldump -u root -ptecmint --all-databases > all-databases.sql



How to Backup MySQL Database Structure Only?

If you only want the backup of database structure without data, then use the option –no-data in the command. The below command exports database [rsyslog] Structure into a file rsyslog_structure.sql.

Mã: Chọn tất cả
mysqldump -u root -ptecmint -–no-data rsyslog > rsyslog_structure.sql



How to Backup MySQL Database Data Only?

To backup database Data only without structure, then use the option –no-create-info with the command. This command takes the database [rsyslog] Data into a file rsyslog_data.sql.

Mã: Chọn tất cả
mysqldump -u root -ptecmint --no-create-db --no-create-info rsyslog > rsyslog_data.sql



How to Backup Single Table of Database?

With the below command you can take backup of single table or certain tables of your database. For example, the following command only take backup of wp_posts table from the database wordpress.

Mã: Chọn tất cả
mysqldump -u root -ptecmint wordpress wp_posts > wordpress_posts.sql



How to Backup Multiple Tables of Database?

If you want to take backup of multiple or certain tables from the database, then separate each table with space.

Mã: Chọn tất cả
mysqldump -u root -ptecmint wordpress wp_posts wp_comments > wordpress_posts_comments.sql



How to Backup Remote MySQL Database

The below command takes the backup of remote server [172.16.25.126] database [gallery] into a local server.

Mã: Chọn tất cả
mysqldump -h 172.16.25.126 -u root -ptecmint gallery > gallery.sql



How to Restore MySQL Database?

In the above tutorial we have seen the how to take the backup of databases, tables, structures and data only, now we will see how to restore them using following format.

Mã: Chọn tất cả
mysql -u [username] –p[password] [database_name] < [dump_file.sql]



How to Restore Single MySQL Database

To restore a database, you must create an empty database on the target machine and restore the database using msyql command. For example the following command will restore the rsyslog.sql file to the rsyslog database.

Mã: Chọn tất cả
mysql -u root -ptecmint rsyslog < rsyslog.sql


If you want to restore a database that already exist on targeted machine, then you will need to use the mysqlimport command.

Mã: Chọn tất cả
mysqlimport -u root -ptecmint rsyslog < rsyslog.sql


In the same way you can also restore database tables, structures and data. If you liked this article, then do share it with your friends.


Read more:
https://www.tecmint.com/mysql-backup-an ... istration/
http://www.mysqltutorial.org/how-to-bac ... ldump.aspx

Những người đã like nghiatichxanh1992 bởi bài viết có ích này:
Hjhj3
Rating: 0.14%
 
nghiatichxanh1992 ✅
Hình đại diện của thành viên
Rank: ☀️2/30☀️
Cấp độ:
Tu luyện:
Like:
Online:
Bang hội: Tiếu Ngạo
Xếp hạng Bang hội: ⚡5/60⚡
Level:
Chủ đề đã tạo: 🩸4140/4140🩸
Tiền mặt:
Ngân hàng:
Nhóm:
Danh hiệu: ⚝Truyền Thuyết⚝
Giới tính:
Ngày tham gia:
Đến từ:
Thiết bị:
Số điện thoại:
(Cốc Cốc 72.4.208)

Re: How To Backup And Restore MySQL On Linux

#2 » Gửi bài gửi bởi Hjhj3 » 17/09/2018 12:51 » @503437

E ngu english nên ko hiểu :)) Like ủng hộ
Hjhj3
Hình đại diện của thành viên
Rank: ☀️10/30☀️
Cấp độ:
Tu luyện:
Like:
Online:
Bang hội: Cầu Vồng
Xếp hạng Bang hội: ⚡3/60⚡
Level:
Chủ đề đã tạo: 🩸14/4140🩸
Tiền mặt:
Ngân hàng:
Nhóm:
Danh hiệu: ⚝Thâu Thiên Hoán Nhật⚝
Giới tính:
Ngày tham gia:
Đến từ:
Số điện thoại:
(Android)

Re: How To Backup And Restore MySQL On Linux

#3 » Gửi bài gửi bởi Dajgiachandat » 18/09/2018 19:14 » @503468

Hjhj 3 đã viết:E ngu english nên ko hiểu :)) Like ủng hộ
Cái này là cơ sở dữ liệu nên hiểu cũng chẳng làm gì
ஜ۩۞۩ஜTrảm Phong Bangஜ۩۞۩ஜ
ஜ۩۞۩ஜPhó Bang Chủஜ۩۞۩ஜ
ஜ۩۞۩ஜDajgiachandatஜ۩۞۩ஜ
░░░░░███████ ]▄▄▄▄▄▄▄▄
I▂▄▅█████████▅▄▃▂I
███████████████████]
.◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...
Wap mình nè
Dajgiachandat ✅
Hình đại diện của thành viên
Rank: ☀️22/30☀️
Cấp độ:
Tu luyện:
Like:
Online:
Bang hội: Trảm Phong
Xếp hạng Bang hội: ⚡1/60⚡
Level:
Chủ đề đã tạo: 🩸106/4140🩸
Tiền mặt:
Nhóm:
Danh hiệu: ⚝Hiệp Khách Cuối Cùng Trên Giang Hồ⚝
Giới tính:
Ngày tham gia:
Đến từ:
Số điện thoại:
(iPhone)



Quay về VPS - Server

 


  • Chủ đề tương tự
    Trả lời
    Xem
    Bài viết mới nhất