用mysqldump和mysqlbinlog的MySQL数据恢复实验(二)

2014-11-24 18:31:14 · 作者: · 浏览: 1
wing.sql。这里要注意路径。


[root@channelme ~]# mysql -uroot -p channel

Enter password:


[root@channelme ~]#


查看恢复结果:


mysql> show tables;


+-------------------------+


| Tables_in_channel |


+-------------------------+


| chanel_following |


| official_channel |


| official_channel_widget |


| personal_channel |


| personal_channel_widget |


| tags |


+-------------------------+


6 rows in set (0.00 sec)


成功。


也可以在mysql下用source命令:


mysql> source \root\chanelfollowing.sql


Query OK, 0 rows affected (0.00sec)


……


Query OK, 0 rows affected (0.00sec)


mysql> showcolumns from chanel_following;


+-------+---------+------+-----+---------+-------+


| Field | Type | Null | Key | Default | Extra |


+-------+---------+------+-----+---------+-------+


| id | int(11) | NO | PRI | NULL | |


| uid | int(11) | NO | | NULL | |


+-------+---------+------+-----+---------+-------+


2 rows in set (0.01 sec)


还原成功。


注意,mysqldump是用来做备份,不能够恢复。恢复用的是mysql命令。



用mysqldump还原到表chanel_following建立,还有数据还没恢复,用mysqlbinlog恢复。


mysql> showbinary logs;


+------------------+-----------+


| Log_name | File_size |


+------------------+-----------+


| mysql-bin.000001 | 29692 |


……


| mysql-bin.000021 | 1571 |


+------------------+-----------+


21 rows in set (0.00 sec)



mysql> showbinlog events in 'mysql-bin.000021';


+------------------+------+-------------+-----------+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+


| Log_name | Pos | Event_type | Server_id |End_log_pos | Info |


+------------------+------+-------------+-----------+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+


| mysql-bin.000021 | 4 | Format_desc | 1 | 107 | Server ver: 5.5.13-log, Binlogver: 4 |


……


| mysql-bin.000021 | 487 | Query | 1 | 621 | use `channel`;create table chanel_following (id int primary key ,uid int not null) |


| mysql-bin.000021 | 621 | Query | 1 | 692 | BEGIN |


| mysql-bin.000021 | 692 | Query | 1 | 843 | use `channel`;insert into chanel_following values(102,100000),(3,69686869),(2132723743,21327237432) |


| mysql-bin.000021 | 843 | Xid | 1 | 870 | COMMIT /* xid=1296 */ |


……


+------------------+------+-------------+-----------+-------------+---------