记一次测试环境mysql崩溃
起因:不小心把uatpub5里的一个表的.ibd直接用truncate –s 0 xxx.ibd删除了导致mysql崩溃起不来
复现:
//Tips1:mysql版本5.7.18复现成功,5.7.23未知
在一台5.7.18的slave上建表qmq.test,然后插入2条数据
//Tips2:若是空表也无法复现,mysql不会崩溃,要有数据才行
然后sudo truncate –s 0 test.ibd,在mysql里对test进行操作之后,mysql崩溃:
mysql> select * from test;
+------+------+
| id | txt |
+------+------+
| 1 | 1 |
| 2 | 2 |
+------+------+
2 rows in set (0.00 sec)
mysql> truncate table test;
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql> select * from test;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
ERROR:
Can't connect to the server
mysql> \q
Bye
[op1@SVR2442HP420 qmq]$ mysql -uus_wyz -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
解决方法:
1. 去另一台机器上建一张相同结构的表,然后执行export:
mysql> flush tables test for export;
Query OK, 0 rows affected (0.00 sec)
2. 在目录中找到自动生成的test.ibd和export后生成的test.cfg
[op1@FATM00003132 wyztestdb]$ ll|grep test
-rw-r--r-- 1 mysql mysql 8672 Jul 31 15:51 test1.frm
-rw-r--r-- 1 mysql mysql 131072 Jul 31 15:51 test1.ibd
-rw-r--r-- 1 mysql mysql 422 Aug 11 18:17 test.cfg
-rw-r--r-- 1 mysql mysql 8584 Aug 11 11:54 test.frm
-rw-r--r-- 1 mysql mysql 98304 Aug 11 18:17 test.ibd
3. 崩溃的机器上把大小是0的test.ibd移走:sudo mv test.ibd /data/tmp/
4. 把2中的2个文件弄过去,改owner到mysql组:chown mysql:mysql
5. 起mysql
[op1@SVR2442HP420 qmq]$ sudo service mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
6. 导入表空间
mysql> alter table test discard tablespace;
Query OK, 0 rows affected, 2 warnings (0.05 sec)
7. mysql> alter table test import tablespace;
Query OK, 0 rows affected (1.62 sec)
8. 随便插条数据成功,mysql恢复
mysql> insert into test select 3,3;
Query OK, 1 row affected (0.04 sec)
Records: 1 Duplicates: 0 Warnings: 0