備份mysql資料庫報告

fuckme36發表於2020-10-09
  1. 冷備份
    1) 停止服務
    [root@centos01 ~]# systemctl stop mysql
    在這裡插入圖片描述

2) 備份資料
[root@centos01 ~]#mkdir /backup
[root@centos01 ~]# tar zcf /backup/mysql_backup-$(date +%F).tar.gz /usr/local/mysql/data/
tar: 從成員名中刪除開頭的“/”
在這裡插入圖片描述
在這裡插入圖片描述

3) 模擬資料庫丟失
[root@centos01 ~]# mv /usr/local/mysql/data/ /opt/ 剪下
在這裡插入圖片描述

4) 恢復資料
[root@centos01 ~]#mkdir restore 建立目錄
[root@centos01 ~]# tar zxf /backup/mysql_backup-2020-06-22.tar.gz -C ./restore
[root@centos01 ~]# mv ./restore/usr/local/mysql/data/ /usr/local/mysql 剪下
在這裡插入圖片描述
在這裡插入圖片描述
在這裡插入圖片描述

5) 重啟服務
systemctl start mysql
在這裡插入圖片描述

  1. 使用mysqldump備份資料庫
    備份資料庫benet中的student表
    在這裡插入圖片描述
    在這裡插入圖片描述
    在這裡插入圖片描述

現插入資料
在這裡插入圖片描述

備份
[root@centos01 ~]# mysqldump -u root -p benet student > benet_student_table.sql
在這裡插入圖片描述

檢視是否備份
[root@centos01 ~]# cat benet_student_table.sql
在這裡插入圖片描述
在這裡插入圖片描述

備份資料庫benet
[root@centos01 ~]# mysqldump -u root -p --databases benet > benet_database.sql
在這裡插入圖片描述

[root@centos01 ~]# cat benet_database.sql
在這裡插入圖片描述

備份所有資料
[root@centos01 ~]# mysqldump -u root -p --opt --all-databases > all_databases
在這裡插入圖片描述

[root@centos01 ~]# cat all_databases
在這裡插入圖片描述

相關文章