标签:nta 实验环境 删掉 scores 进制 lld gen sel 连接mysql
一 实验目标1 掌握mysqldump用法
2 掌握 mysqldump 完全备份,增量备份
3 掌握 mysqldump 恢复数据库,二进制日志即时点还原
操作系统:CentOS release 6.8 (Final)
应用软件:percona-server-5.6.29-76.2
周完全+每日增量
完全备份: 使用mysqldump备份所有库
增量备份: 备份二进制日志文件
导入jiaowu.sql 数据
[root@paul ~]# mysql < /root/jiaowu.sql
[root@paul ~]# mysql
mysql> show databases;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.10 sec)
mysql> use jiaowu;
mysql> show tables;
+------------------+
| Tables_in_jiaowu |
+------------------+
| courses |
| scores |
| students |
| tutors |
+------------------+
[root@paul ~]# mysqldump -uroot -p --master-data=2 --lock-all-tables --flush-logs --all-databases > /root/alldatabases.sql
连接mysql
[root@paul ~]# mysql
mysql> SHOW BINARY LOGS;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 10389 |
| mysql-bin.000002 | 120 |
+------------------+-----------+
删掉旧二进制日志
mysql> PURGE BINARY LOGS TO ‘mysql-bin.000002‘;
Query OK, 0 rows affected (0.01 sec)
模拟数据库修改,删掉部分数据
[root@paul ~]# mysql
mysql> use jiaowu;
mysql> SELECT * FROM tutors;
+-----+--------------+--------+------+
| TID | Tname | Gender | Age |
+-----+--------------+--------+------+
| 1 | HongQigong | M | 93 |
| 2 | HuangYaoshi | M | 63 |
| 3 | Miejueshitai | F | 72 |
| 4 | OuYangfeng | M | 76 |
| 5 | YiDeng | M | 90 |
| 6 | YuCanghai | M | 56 |
| 7 | Jinlunfawang | M | 67 |
| 8 | HuYidao | M | 42 |
| 9 | NingZhongze | F | 49 |
+-----+--------------+--------+------+
mysql> DELETE FROM tutors WHERE Age>90;
Query OK, 1 row affected (0.00 sec)
mysql> FLUSH LOGS;
mysql> SHOW BINARY LOGS;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000002 | 390 |
| mysql-bin.000003 | 120 |
+------------------+-----------+
mysql> quit;
[root@paul ~]# ls -l /data/mysql
[root@paul ~]# cp -a /data/mysql/mysql-bin.000002 /root/
将二进制日志文件转换为sql脚本
[root@paul ~]# mysqlbinlog /root/mysql-bin.000002 > /root/mon-incremental.sql
[root@paul ~]# mysql
mysql> use jiaowu;
mysql> INSERT INTO tutors (Tname) VALUES (‘stu123‘);
mysql> FLUSH LOGS;
mysql> SHOW BINARY LOGS;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000002 | 390 |
| mysql-bin.000003 | 435 |
| mysql-bin.000004 | 120 |
+------------------+-----------+
mysql> QUIT;
备份第二天二进制日志文件
[root@paul ~]# cp -a /data/mysql/mysql-bin.000003 /root/
[root@paul ~]# rm -rf /data/mysql/*
[root@paul ~]# service mysqld stop
MySQL (Percona Server) PID file could not be found! [FAILED]
[root@paul ~]# killall mysqld
初始化mysql
[root@paul ~]# /usr/local/mysql/scripts/mysql_install_db
--user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
[root@paul ~]# service mysqld start
[root@paul ~]# mysql -uroot -p < /root/alldatabases.sql
[root@paul ~]# mysqlbinlog /root/mysql-bin.000002 | mysql -uroot –p
[root@paul ~]# mysqlbinlog /root/mysql-bin.000003 | mysql -uroot -p
标签:nta 实验环境 删掉 scores 进制 lld gen sel 连接mysql
原文地址:http://blog.51cto.com/437549/2330106