痛点:数据库启动不了,无法得知库中的建表语句
思路:先找到之前建表语句,再重新建一个新库,在新库中执行建表sql,将新库中的表空间取除,再将旧库里的idb文件复制到新库中,加载表空间,最后查询数据验证
解决:
1.去mysql官网下载mysql-utilities-1.6.5-1.el7.noarch软件
安装mysql-utilities-1.6.5-1.el7.noarch 软件
安装:用下面2个命令
python ./setup.py build
python ./setup.py sinstall
2.使用下面命令就查看frm文件的建表语句:
mysqlfrm –diagnostic /usr/local/mysql/data/test/*.frm >/tmp/a.sql
3.重新初始化一个新库,将建表语句批量执行
进入到新库中:source /tmp/a.sql;
4.进入到新库中 移除新建表的表空间
如果有多张表 可以用concat拼接语句
> select concat("alter table world.",table_name,"discard tablespace;") from information_schema.tables where table_schema='world';
4.使用cp将旧库里的idb文件移动到新库中
cp *.idb .
chown -R mysql. *
5.加载表空间,如果表多也可以拼接
select concat("alter table world.",table_name,"import tablespace;") from information_schema.tables where table_schema='world';