数据恢复新姿势:使用MySQL Shell进行更高效灵活的数据恢复
上篇文章(转战MySQL Shell!数据库备份新姿势,轻松搞定备份操作!)简单介绍了使用MySQL Shell进行数据库备份,本文基于上文的备份进行数据恢复演示操作。
1. 恢复单表
因为上次备份的表是testdb1.test1表,如果恢复到当前库,则可以先删除该库中的表,再恢复。
1.1 先删除库里的表
# mysqlsh -u root -p -S data/mysql/mysql3306/tmp/mysql.sock
Please provide the password for 'root@/data%2Fmysql%2Fmysql3306%2Ftmp%2Fmysql.sock': *********
Save password for 'root@/data%2Fmysql%2Fmysql3306%2Ftmp%2Fmysql.sock'? [Y]es/[N]o/Ne[v]er (default No):
MySQL Shell 8.0.35
<br>
Copyright (c) 2016, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
<br>
Type 'help' or '?' for help; 'quit' to exit.
Creating a session to 'root@/data%2Fmysql%2Fmysql3306%2Ftmp%2Fmysql.sock'
Fetching schema names for auto-completion... Press ^C to stop.
Your MySQL connection id is 83
Server version: 8.0.33-25 Percona Server (GPL), Release 25, Revision 60c9e2c5
No default schema selected; type use to set one.
MySQL localhost JS > sql
Switching to SQL mode... Commands end with ;
Fetching global names for auto-completion... Press ^C to stop.
MySQL localhost SQL > use testdb1;
Default schema set to `testdb1`.
Fetching global names, object names from `testdb1` for auto-completion... Press ^C to stop.
MySQL localhost testdb1 SQL > show tables;
+-------------------+
| Tables_in_testdb1 |
+-------------------+
| test1 |
+-------------------+
1 row in set (0.0010 sec)
MySQL localhost testdb1 SQL > drop table test1;
Query OK, 0 rows affected (0.0518 sec)
MySQL localhost testdb1 SQL >
<br>