MySQL备份与恢复之热备(3)

2019-01-04 21:51:50于海丽

第五步,模拟数据丢失,进入MySQL,删除数据库

[root@serv01 data]# mysql -uroot -p123456 Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 4 Server version: 5.5.29-log Source distribution Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | crm | | game | | hello | | larrydb | | mnt | | mysql | | performance_schema | | test | +--------------------+ 9 rows in set (0.00 sec) mysql> drop database larrydb; Query OK, 2 rows affected (0.01 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | crm | | game | | hello | | mnt | | mysql | | performance_schema | | test | +--------------------+ 8 rows in set (0.00 sec) mysql> exit Bye

第六步,导入数据

[root@serv01 databackup]# mysql -uroot -p123456 <larrydb.sql

 
第七步,登录MySQL,查看数据是否正常

[root@serv01 data]# mysql -uroot -p123456 Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 6 Server version: 5.5.29-log Source distribution Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> show database; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | crm | | game | | hello | | larrydb | | mnt | | mysql | | performance_schema | | test | +--------------------+ 9 rows in set (0.00 sec) mysql> use larrydb; Database changed mysql> select * from class; +------+--------+ | cid | cname | +------+--------+ | 1 | linux | | 2 | oracle | +------+--------+ 2 rows in set (0.00 sec) mysql> select * from stu; +------+---------+------+ | sid | sname | cid | +------+---------+------+ | 1 | larry01 | 1 | | 2 | larry02 | 2 | +------+---------+------+ 2 rows in set (0.00 sec)

对多个库进行备份
第一步,查看有哪些数据库

mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | crm | | game | | hello | | larrydb | | mnt | | mysql | | performance_schema | | test | +--------------------+ 9 rows in set (0.00 sec) mysql> use game; Database changed mysql> show tables; +----------------+ | Tables_in_game | +----------------+ | country | | fight | | hero | +----------------+ 3 rows in set (0.00 sec) mysql> select * from country; +-----+---------+----------+ | cno | cname | location | +-----+---------+----------+ | 10 | caowei | luoyang | | 20 | shuhan | chengdou | | 30 | sunwu | nanjing | | 40 | houhan | luoyang | | 50 | beisong | kaifeng | | 60 | 魏国 | 洛阳 | +-----+---------+----------+ 6 rows in set (0.00 sec)