Mysql 无法启动 - ibdata1 损坏?- 操作系统错误编号 13 - 权限问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3907666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mysql won't start - ibdata1 corrupt? - operating system error number 13 - permissions issue
提问by eat_a_lemon
Server shutdown from power failure.
Mysql will not start now.
Disk is not full.
Syslog is below
服务器因电源故障而关闭。
Mysql 现在不会启动。
磁盘未满。系统日志如下
Oct 11 15:03:31 joe mysqld_safe[24757]: started
Oct 11 15:03:31 joe mysqld[24760]: 101011 15:03:31 InnoDB: Operating system error number 13 in a file operation.
Oct 11 15:03:31 joe mysqld[24760]: InnoDB: The error means mysqld does not have the access rights to
Oct 11 15:03:31 joe mysqld[24760]: InnoDB: the directory.
Oct 11 15:03:31 joe mysqld[24760]: InnoDB: File name ./ibdata1
Oct 11 15:03:31 joe mysqld[24760]: InnoDB: File operation call: 'create'.
Oct 11 15:03:31 joe mysqld[24760]: InnoDB: Cannot continue operation.
采纳答案by Morgan Tocker
The file is not corrupt. You can find out the source of these errors with 'perror'. i.e.
该文件没有损坏。您可以使用“perror”找出这些错误的来源。IE
toaster:~ morgo$ perror 13
OS error code 13: Permission denied
InnoDB has corruption detection (page checksums) and would happily tell you if that were the problem.
InnoDB 具有损坏检测(页面校验和),并且很乐意告诉您这是否是问题所在。
Either the directory permissions have changed, or your my.cnf file has been hosed, and it's trying to recreate data files somewhere else.
目录权限已更改,或者您的 my.cnf 文件已被处理,并且它正在尝试在其他地方重新创建数据文件。
回答by Dan
If you are using ubuntu or apparmor you should permit this change in apparmor.
如果您使用的是 ubuntu 或 apparmor,您应该在 apparmor 中允许此更改。
Edit /etc/apparmor.d/usr.sbin.mysqld
and change /var/lib/mysql
with the new DATADIR
.
编辑/etc/apparmor.d/usr.sbin.mysqld
和更改/var/lib/mysql
与新的DATADIR
。
It should work.
它应该工作。
回答by Carlos Omar Brise?o Gutierrez
Error:
错误:
101130 14:42:51 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended 101130 18:07:58 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 101130 18:07:58 InnoDB: Operating system error number 13 in a file operation. InnoDB: The error means mysqld does not have the access rights to InnoDB: the directory. InnoDB: File name ./ibdata1 InnoDB: File operation call: 'open'. InnoDB: Cannot continue operation.
Solution SeLinux SeLinux security:
解决方案 SeLinux SeLinux 安全性:
[root@localhost ~]# service mysqld restart Deteniendo mysqld: [ OK ] Iniciando mysqld: [ FALLó ] [root@localhost ~]# restorecon -R /var/lib/mysql/ [root@localhost ~]# service mysqld restart Deteniendo mysqld: [ OK ] Iniciando mysqld: [ OK ] [root@localhost ~]#
回答by dordal
For me, restoring the security context (selinux) did the trick
对我来说,恢复安全上下文 (selinux) 成功了
restorecon -R /var/lib/mysql/
restorecon -R /var/lib/mysql/
回答by IndikatorDesign
please check this:
请检查这个:
chown -R mysql:mysql /var/lib/mysql
回答by Levite
In short, (especially on RHEL/CentOS/Fedora) try
总之,(尤其是在 RHEL/CentOS/Fedora 上)尝试
getenforce
if it replies with Enforcing
you have SELinux up and running. Temporarily deactivate it with setenforce 0
and see if MariaDB starts now! Rather common, especially on RHEL/CentOS/Fedora.
如果它回复Enforcing
你已经启动并运行了 SELinux。暂时停用它,setenforce 0
看看 MariaDB 现在是否启动!相当普遍,尤其是在 RHEL/CentOS/Fedora 上。
There's more about this further down, as well as in this official article.
还有更多关于这个的更多信息,以及这篇官方文章。
In general
一般来说
There are more things in a UNIX environment that might prevent file access, than just user access rights.
在 UNIX 环境中,除了用户访问权限之外,还有更多的东西可能会阻止文件访问。
- Security modules like SELinux (see above) or AppArmor (as Dan mentioned) could disallow it
- Access Control Lists (ACL) could be specifically set, for the required files/directories
- Any of the parent folders could be owned by another user, and have no x (="dir access") set for others
- SELinux(见上文)或 AppArmor(如 Dan 提到的)等安全模块可能会禁止它
- 可以为所需的文件/目录专门设置访问控制列表 (ACL)
- 任何父文件夹都可以由另一个用户拥有,并且没有为其他人设置 x (="dir access")
Additionally there could be other unexpected factors, like ...
此外,可能还有其他意想不到的因素,例如...
- The mysql
datadir
being set to a place, where mysql doesn't have permissions (see/etc/my.cnf
) - Mysql could (strangely) be running as a different user, or the file could be simply owned by someone else
- mysql
datadir
被设置为 mysql 没有权限的地方(请参阅/etc/my.cnf
) - Mysql 可能(奇怪)以不同的用户身份运行,或者该文件可能只是由其他人拥有
Just to mention a view things off the top of my head (feel free to edit/add to this answer btw).
只是提一下我头脑中的一个观点(顺便说一下,随意编辑/添加到这个答案)。
In the case, SELinux is "the problem"
在这种情况下,SELinux 是“问题”
For a permanent solution, you could try to restore the appropriate security context, ...
对于永久解决方案,您可以尝试恢复适当的安全上下文,...
restorecon -R /var/lib/mysql/
... or just deactivate SELinux (but think about this one a little bit before doing so), by editing the config (typically in /etc/selinux/config
) and setting SELINUX=disabled
as suggested in following article.
... 或者只是停用 SELinux(但在这样做之前先考虑一下这个),方法是编辑配置(通常在 中/etc/selinux/config
)并SELINUX=disabled
按照以下文章中的建议进行设置。
- Here the officialhelp page from mariadb.com: What to do if MariaDB doesn't start
- And here something from redhat.com: MariaDB Changing Database Location
- 这里是mariadb.com的官方帮助页面:如果 MariaDB 没有启动怎么办
- 来自 redhat.com 的一些内容:MariaDB 更改数据库位置
Obviously those are applicable to MySQL just the same way.
显然,这些同样适用于 MySQL。
回答by A Nun Famous
I had exactly the same problem on my CentOS box. After moving mysql data directory around I couldn't start the service anymore, even as I had copied the files with the same owner and permissions.
我在 CentOS 机器上遇到了完全相同的问题。移动 mysql 数据目录后,我无法再启动该服务,即使我复制了具有相同所有者和权限的文件。
I had a problem with the SELinux security context. If you run your CentOS stock it has good chance to be enabled and won't let do what you want with MySQL. To fix this :
我遇到了 SELinux 安全上下文的问题。如果你运行你的 CentOS 股票,它很有可能被启用并且不会让你用 MySQL 做你想做的事。要解决这个问题:
First compare the old dir and new dir using
首先使用比较旧目录和新目录
ls -Z /var/lib/mysql
and
和
ls -Z /new/mysql/dir
If you see any difference it's likely to be your problem. To modify this :
如果您看到任何差异,则很可能是您的问题。要修改这个:
chcon -R --type=mysql_db_t /new/mysql/dir
The -R switch is for recursion. If you only need to change one file you can omit it. If your context is different than mine(maybe a different distro), use the one indicated by the output of the first (it should be the 3rd field of the SELinux stuff)
-R 开关用于递归。如果您只需要更改一个文件,您可以省略它。如果您的上下文与我的不同(可能是不同的发行版),请使用第一个输出指示的上下文(它应该是 SELinux 内容的第三个字段)
ls -Z /var/lib/mysql
回答by Rohit Gupta
I had the same problem and fix by below steps
我遇到了同样的问题并通过以下步骤修复
Working directory /var/lib/mysql
工作目录 /var/lib/mysql
Earlier /var/lib/mysql was owned by some unknown user
较早的 /var/lib/mysql 由某个未知用户拥有
Changed it to mysql
改成mysql
mysql]# chown -R mysql:mysql *
mysql]# chown -R mysql:mysql *
mysql]# service mariadb start
mysql]# service mariadb start
Redirecting to /bin/systemctl start mariadb.service
Redirecting to /bin/systemctl start mariadb.service
Works like a charm
奇迹般有效
回答by John Creamer
When this popped up for me, I found the answer in the /etc/mysql/my.cnf
configuration file. The datadir
line did not point to the /var/lib/mysql
directory (where the databases are). Once I put this path in, the server restarted no problem.
当这对我弹出时,我在/etc/mysql/my.cnf
配置文件中找到了答案。该datadir
行没有指向/var/lib/mysql
目录(数据库所在的目录)。一旦我把这个路径放进去,服务器重启就没有问题了。
回答by A Nun Famous
I had exactly the same problem on my CentOS box. After moving mysql data directory around I couldn't start the service anymore, even as I had copied the files with the same owner and permissions.
我在 CentOS 机器上遇到了完全相同的问题。移动 mysql 数据目录后,我无法再启动该服务,即使我复制了具有相同所有者和权限的文件。
I had a problem with the SELinux security context. If you run your CentOS stock it has good chance to be enabled and won't let do what you want with MySQL. To fix this :
我遇到了 SELinux 安全上下文的问题。如果你运行你的 CentOS 股票,它很有可能被启用并且不会让你用 MySQL 做你想做的事。要解决这个问题:
First compare the old dir and new dir using
首先使用比较旧目录和新目录
ls -Z /var/lib/mysql
and
和
ls -Z /new/mysql/dir
If you see any difference it's likely to be your problem. To modify this :
如果您看到任何差异,则很可能是您的问题。要修改这个:
chcon -R --type=mysql_db_t /new/mysql/dir
The -R switch is for recursion. If you only need to change one file you can omit it.
-R 开关用于递归。如果您只需要更改一个文件,您可以省略它。