最近,我做了一个实验,就是想验证mysql在丢失表数据文件的情况下,数据库是否能正常启动,发现启动正常。
个人感觉mysql这么做不太安全,因为管理员可能都不知道丢失数据文件了。不过,还好,可以观察错误日志文件来发现丢失数据文件的信息。所以,我们在启动mysql的过程中,一定别忘了仔细观察错误日志文件,以便及时发现数据库潜在问题。
下面就是我的过程:
1、关闭MySQL数据库
[root@drbd-01 db1]# service mysqld stop
Shutting down MySQL (Percona Server).......................[确定]...
2、删除MySQL的一个数据文件
[root@drbd-01 db1]# cd /data/mysql/data/db1
[root@drbd-01 db1]# mv t1.ibd t1.ibd.bak
[root@drbd-01 db1]# mv t1.frm t1.frm.bak
[root@drbd-01 db1]# ls
db.opt t1.frm.bak t1.ibd.bak
3、重新启动MySQL
[root@drbd-01 db1]# service mysqld start
Starting MySQL (Percona Server).............................................................. [确定]
在丢失数据文件 t1.ibd 的情况下,数据库居然启动起来了(这在oracle里面简直是不允许的)
4、验证
(root@localhost)[(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.17 sec)
(root@localhost)[(none)]> use db1;
Database changed
(root@localhost)[db1]> show tables;
Empty set (0.00 sec)
发现t1表果真不存在了。
(root@localhost)[db1]> create table t1 (id int);
ERROR 1813 (HY000): Tablespace for table '`db1`.`t1`' exists. Please DISCARD the tablespace before IMPORT.
又不让建立t1表,好尴尬。
5、查看错误日志(还好错误日志告诉我们数据文件曾经存在但现在丢了 )
[root@drbd-01 db1]# tail -100 /data/mysql/logs/mysql-error.log
InnoDB: directories yourself, InnoDB does not create them.
2016-01-08 16:43:12 10462 [ERROR] InnoDB: Could not find a valid tablespace file for 'db1/t1'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2016-01-08 16:43:12 10462 [ERROR] InnoDB: Tablespace open failed for '"db1"."t1"', ignored.
2016-01-08 16:43:12 10462 [Note] InnoDB: 128 rollback segment(s) are active.
2016-01-08 16:43:12 10462 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.6.27-76.0 started; log sequence number 1689915
2016-01-08 16:43:13 10462 [ERROR] InnoDB: Failed to find tablespace for table '"db1"."t1"' in the cache. Attempting to load the tablespace with space id 7.
2016-01-08 16:43:13 7f266daba700 InnoDB: Operating system error number 2 in a file operation.
InnoDB: The error means the system cannot find the path specified.
2016-01-08 16:43:13 10462 [ERROR] InnoDB: Could not find a valid tablespace file for 'db1/t1'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2016-01-08 16:43:13 10462 [Note] Server hostname (bind-address): '*'; port: 3306
2016-01-08 16:43:13 10462 [Note] IPv6 is available.
6、结论
在MySQL数据库启动时,管理员别忘了仔细观察你的错误日志,以便及时发现问题。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28916011/viewspace-1973991/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28916011/viewspace-1973991/