发布网友 发布时间:2022-04-21 14:00
共3个回答
懂视网 时间:2022-04-08 15:37
应该经常对二进制文件做增量备份,例如每过半填,让二进制日志自动滚动一次,把之前的备份起来。
示例: [root@testserver ~]# mysqldump -uroot --databases hellodb --lock-tables --master-data=2 > /root/hellodbbak.sql [root@testserver ~]# less hellodbbak.sql | grep CHANGE -- CHANGE MASTER TO MASTER_LOG_FILE=‘mysql-bin.000011‘, MASTER_LOG_POS=7655;#这样就得到了当前使用的二进制日志文件名和当前记录位置 修改当前库里的某些数据: MariaDB [hellodb]> INSERT INTO students (Name,Age,Gender,ClassID,TeacherID) VALUES (‘Chao Gai‘,47,‘M‘,3,7); Query OK, 1 row affected (0.00 sec) DELETE FROM students WHERE StuID=3; Query OK, 1 row affected (0.00 sec) 此时mysql服务器挂了,我们把数据还原到另一个服务器上,执行恢复操作: 还原前要注意先要关掉Bin_log set bin_log=0,等还原完了再开启bin_log [root@node1 ~]# mysql < hellodbbak.sql 查看恢复的状况:发现没有完全恢复:晁盖没进来,谢烟客还在 MariaDB [hellodb]> SELECT * FROM students; +-------+---------------+-----+--------+---------+-----------+ | StuID | Name | Age | Gender | ClassID | TeacherID | +-------+---------------+-----+--------+---------+-----------+ | 1 | Shi Zhongyu | 22 | M | 2 | 3 | | 2 | Shi Potian | 22 | M | 1 | 7 | | 3 | Xie Yanke | 53 | M | 2 | 16 | | 4 | Ding Dian | 32 | M | 4 | 4 | | 5 | Yu Yutong | 26 | M | 3 | 1 | | 6 | Shi Qing | 46 | M | 5 | NULL | | 7 | Xi Ren | 19 | F | 3 | NULL | | 8 | Lin Daiyu | 17 | F | 7 | NULL | | 9 | Ren Yingying | 20 | F | 6 | NULL | | 10 | Yue Lingshan | 19 | F | 3 | NULL | | 11 | Yuan Chengzhi | 23 | M | 6 | NULL | | 12 | Wen Qingqing | 19 | F | 1 | NULL | | 13 | Tian Boguang | 33 | M | 2 | NULL | | 14 | Lu Wushuang | 17 | F | 3 | NULL | | 15 | Duan Yu | 19 | M | 4 | NULL | | 16 | Xu Zhu | 21 | M | 1 | NULL | | 17 | Lin Chong | 25 | M | 4 | NULL | | 18 | Hua Rong | 23 | M | 7 | NULL | | 19 | Xue Baochai | 18 | F | 6 | NULL | | 20 | Diao Chan | 19 | F | 7 | NULL | | 21 | Huang Yueying | 22 | F | 6 | NULL | | 22 | Xiao Qiao | 20 | F | 1 | NULL | | 23 | Ma Chao | 23 | M | 4 | NULL | | 24 | Xu Xian | 27 | M | NULL | NULL | | 25 | Sun Dasheng | 100 | M | NULL | NULL | +-------+---------------+-----+--------+---------+-----------+ 25 rows in set (0.00 sec) 继续使用二进制文件恢复:根据上面列出来的二进制日志文件和当前记录位置 [root@testserver ~]# mysqlbinlog --start-position=7655 /mydata/data/mysql-bin.000011 > incre.sql 看一下这个二进制日志文件: [root@testserver ~]# mysqlbinlog --start-position 7655 /mydata/data/mysql-bin.000011 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #151110 21:35:57 server id 1 end_log_pos 245 Start: binlog v 4, server v 5.5.44-MariaDB-log created 151110 21:35:57 at startup # Warning: this binlog is either in use or was not closed properly. ROLLBACK/*!*/; BINLOG ‘ vfJBVg8BAAAA8QAAAPUAAAABAAQANS41LjQ0LU1hcmlhREItbG9nAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAC98kFWEzgNAAgAEgAEBAQEEgAA2QAEGggAAAAICAgCAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAA8nm5Lg== ‘/*!*/; # at 7655 #151110 23:14:20 server id 1 end_log_pos 7726 Query thread_id=10 exec_time=0 error_code=0 SET TIMESTAMP=1447168460/*!*/; SET @@session.pseudo_thread_id=10/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; SET @@session.sql_mode=0/*!*/; SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; /*!C utf8 *//*!*/; SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/; SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; BEGIN /*!*/; # at 7726 #151110 23:14:20 server id 1 end_log_pos 7754 Intvar SET INSERT_ID=26/*!*/; # at 7754 #151110 23:14:20 server id 1 end_log_pos 7907 Query thread_id=10 exec_time=0 error_code=0 use `hellodb`/*!*/; SET TIMESTAMP=1447168460/*!*/; INSERT INTO students (Name,Age,Gender,ClassID,TeacherID) VALUES (‘Chao Gai‘,47,‘M‘,3,7) /*!*/; # at 7907 #151110 23:14:20 server id 1 end_log_pos 7934 Xid = 780 COMMIT/*!*/; # at 7934 #151110 23:16:55 server id 1 end_log_pos 8005 Query thread_id=10 exec_time=0 error_code=0 SET TIMESTAMP=1447168615/*!*/; BEGIN /*!*/; # at 8005 #151110 23:16:55 server id 1 end_log_pos 8105 Query thread_id=10 exec_time=0 error_code=0 SET TIMESTAMP=1447168615/*!*/; DELETE FROM students WHERE StuID=3 /*!*/; # at 8105 #151110 23:16:55 server id 1 end_log_pos 8132 Xid = 781 COMMIT/*!*/; DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; 拷贝到那台好的服务器进行还原: [root@testserver ~]# scp incre.sql root@192.168.3.131:/root/ root@192.168.3.131‘s password: incre.sql 100% 2373 2.3KB/s 00:00 [root@node1 ~]# mysql < incre.sql 查看:发现谢烟客没了,晁盖来了,数据被完整恢复了! +-------+---------------+-----+--------+---------+-----------+ | StuID | Name | Age | Gender | ClassID | TeacherID | +-------+---------------+-----+--------+---------+-----------+ | 1 | Shi Zhongyu | 22 | M | 2 | 3 | | 2 | Shi Potian | 22 | M | 1 | 7 | | 4 | Ding Dian | 32 | M | 4 | 4 | | 5 | Yu Yutong | 26 | M | 3 | 1 | | 6 | Shi Qing | 46 | M | 5 | NULL | | 7 | Xi Ren | 19 | F | 3 | NULL | | 8 | Lin Daiyu | 17 | F | 7 | NULL | | 9 | Ren Yingying | 20 | F | 6 | NULL | | 10 | Yue Lingshan | 19 | F | 3 | NULL | | 11 | Yuan Chengzhi | 23 | M | 6 | NULL | | 12 | Wen Qingqing | 19 | F | 1 | NULL | | 13 | Tian Boguang | 33 | M | 2 | NULL | | 14 | Lu Wushuang | 17 | F | 3 | NULL | | 15 | Duan Yu | 19 | M | 4 | NULL | | 16 | Xu Zhu | 21 | M | 1 | NULL | | 17 | Lin Chong | 25 | M | 4 | NULL | | 18 | Hua Rong | 23 | M | 7 | NULL | | 19 | Xue Baochai | 18 | F | 6 | NULL | | 20 | Diao Chan | 19 | F | 7 | NULL | | 21 | Huang Yueying | 22 | F | 6 | NULL | | 22 | Xiao Qiao | 20 | F | 1 | NULL | | 23 | Ma Chao | 23 | M | 4 | NULL | | 24 | Xu Xian | 27 | M | NULL | NULL | | 25 | Sun Dasheng | 100 | M | NULL | NULL | | 26 | Chao Gai | 47 | M | 3 | 7 | +-------+---------------+-----+--------+---------+-----------+ 25 rows in set (0.00 sec)
本文出自 “明天过后” 博客,请务必保留此出处http://leeyan.blog.51cto.com/8379003/1711630
mariadb备份与恢复工具
标签:mysql 备份 mysqldump 恢复 xtrabackup
热心网友 时间:2022-04-08 12:45
有oracle和mysql 但是在刘遄老师的《linux就该这么学》第18章 使用MariaDB数据库管理系统 中这样写道:
MYSQL数据库管理系统被Oracle公司收购后从开源换向到了封闭,导致包括红帽在内的许多Linux发行版选择了MariaDB。本章节将教会您使用mariaDB数据库管理工具来管理数据库,学习对数据表单的新建、搜索、更新、插入、删除等常用操作。并且熟练掌握对数据库内用户的创建与授权,数据库的备份与恢复方法,不仅满足了RHCE考题要求,还能帮助您的运维工作。
所以建议学习下MariaDB,具体的操作可参考下:http://www.linuxprobe.com/chapter-18.html
热心网友 时间:2022-04-08 14:03
主流的数据库在linux中都用,比如oracle和mysql