Bang hộiTiền mặt: 0 Xu Trò chơiHộp quà giáng sinhThứ Sáu, 18:15:14 - 29/03/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

[Linux] How to backup and restore MySQL databases on Linux

[Linux] How to backup and restore MySQL databases on Linux

#1 » Gửi bài gửi bởi nghiatichxanh1992 » 28/11/2021 02:50 » @524355

How to backup and restore MySQL databases on Linux


A simple and easy method for creating MySQL backups is to use the mysqldump command. This command will create a simple .sql file of an existing database, which can then be restored to any other empty MySQL database. This article will work for any Linux distribution running MySQL.


1. Back up the database using the following command:

mysqldump -u [username] –p[password] [database_name] > [dump_file.sql]
Example: mysqldump -u root data112021 > data112021.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.


2. Restore the backup to a local database server - the mysql command will let you take the contents of a .sql file backup, and restore it directly to a database. This is the syntax for the command:

mysql -u [username] –p[password] [database_name] < [dump_file.sql]
Example: mysql -u root data112021 < data112021.sql

3. Restore the backup to a remote database server - you can also use the mysql command to restore a .sql file backup to a remote MySQL server. If you have another server running MySQL, and you have the database credentials, you can define a hostname in the command by adding the -h flag to specify a hostname. This changes the syntax of the command to:

mysql –h [hostname] –u [username] –p[password] [database_name] < [dump_file.sql]
Example: mysql –h -u root data112021 < data112021.sql

As long as you have the correct credentials and the remote server is running, you will be able to restore the database remotely.
Sửa lần cuối: nghiatichxanh1992 28/11/2021 03:06
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: 🩸4142/4142🩸
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:
(Google Chrome 97.0.469)


Quay về VPS - Server

 


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