【环境说明】
CentOS 6.8(默认开启了SELinux)使用YUM安装搭建的Mysql社区版;
【问题现象】
关闭Mysql服务;
删除当前数据目录/var/lib/mysql中的所有文件;
使用之前/var/lib/mysql目录的备份文件解压覆盖;
启动Mysql服务,启动失败;
查询Mysql日志文件/var/log/mysqld.log如下报错
2018-02-01T09:06:39.475244Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2018-02-01T09:06:39.475316Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2018-02-01T09:06:39.475321Z 0 [ERROR] InnoDB: os_file_get_status() failed on './ibdata1'. Can't determine file permissions
2018-02-01T09:06:39.475325Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2018-02-01T09:06:40.079659Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2018-02-01T09:06:40.079690Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2018-02-01T09:06:40.079695Z 0 [ERROR] Failed to initialize builtin plugins.
2018-02-01T09:06:40.079698Z 0 [ERROR] Aborting
【解决方案】
# chcon -Rt mysqld_db_t /var/lib/mysql
# chcon -Ru system_u /var/lib/mysql
# chown -R mysql:mysql /var/lib/mysql
# service mysqld start
启动正常