MySQL8使用物理文件恢复MyISAM表测试

举报
OrangeDBM 发表于 2025/04/23 14:28:06 2025/04/23
【摘要】 我们现场测试一个场景,drop一张MyISAM表后,单独对这表进行物理恢复首先我们看一下secure_file_priv文件目录的位置mysql> show global variables like ‘%secure_file_priv%’;±-----------------±--------------------+| Variable_name Value±--------...

我们现场测试一个场景,drop一张MyISAM表后,单独对这表进行物理恢复

首先我们看一下secure_file_priv文件目录的位置

mysql> show global variables like ‘%secure_file_priv%’;
±-----------------±--------------------+
| Variable_name Value
±-----------------±--------------------+
| secure_file_priv | /u01/mysql3308/tmp/ |
±-----------------±--------------------+

如果没有设置这个选项,我们可以在my.cnf配置文件里添加这一项,放在[mysqld]下

[root@mysql8_3 mysql3308]# more my.cnf | grep secure_file
secure_file_priv=/u01/mysql3308/tmp

修改好配置后需要重启一下服务

[root@mysql8_3 mysql3308]# systemctl stop mysqld83308.service
[root@mysql8_3 mysql3308]# systemctl start mysqld83308.service

登录到实例查看是否生效

mysql> show global variables like ‘%secure_file_priv%’;
±-----------------±--------------------+
| Variable_name Value
±-----------------±--------------------+
| secure_file_priv | /u01/mysql3308/tmp/ |
±-----------------±--------------------+

我们看一下测试表

[root@mysql8_3 test]# mysql -uroot -p
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed

测试表tmyisam当前有一条数据

mysql> select * from tmyisam;
±-----+
| i |
±-----+
| 1 |
±-----+
1 row in set (0.00 sec)

现在我们手动备份tmyisam表的物理文件

[root@mysql8_3 test]# cp tmyisam* /tmp/

备份完后删除该表

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
±---------------+
| Tables_in_test |
±---------------+
| employees|
| tarchive|
| tblackhole|
| tinnodb|
| tmemory|
| tmyisam|
±---------------+
6 rows in set (0.00 sec)
mysql> drop table tmyisam;
Query OK, 0 rows affected (0.20 sec)
mysql> exit
Bye

删除完成后,我们手动拷贝tmyisam表数据文件tmyisam.MYD和表索引文件到数据库目录并修改属性

[root@mysql8_3 test]# cp /tmp/tmyisam.MYI /u01/mysql3308/data/test/
[root@mysql8_3 test]# cp /tmp/tmyisam.MYD /u01/mysql3308/data/test/
[root@mysql8_3 test]# chown -R mysql:mysql tmyisam.MYI
[root@mysql8_3 test]# chown -R mysql:mysql tmyisam.MYD

然后拷贝表结构文件tmyisam_392.sid到安全目录,并修改该文件的属主

[root@mysql8_3 test]# cp /tmp/tmyisam_392.sdi /u01/mysql3308/tmp/
[root@mysql8_3 test]# chown -R mysql:mysql tmyisam_392.sdi

然后我们登录到数据库执行导入

[root@mysql8_3 test]# mysql -uroot -p
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
mysql> import table from ‘/u01/mysql3308/tmp/tmyisam_392.sdi’;
Query OK, 0 rows affected (0.02 sec)
mysql> select * from tmyisam;
±-----+
| i |
±-----+
| 1 |
±-----+
1 row in set (0.00 sec)
mysql>

tmyisam表完成恢复
6qrt4xwe6vjg6_817b7a0b3c254ca19eb7ab57a2b678ea.png

【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。