将 MySQL 数据库复制到另一台机器
我正在尝试在另一台服务器上创建 MySQL 数据库的副本。我停止服务器,压缩 mysql 目录,将其复制到另一台服务器并解压缩。我设置了所有权限以匹配工作服务器,并复制了 my.cnf 文件,因此除了服务器特定的更改之外,一切都是相同的。
但是,当我尝试启动服务器时,出现以下 InnoDB 错误:
InnoDB: Operating system error number 13 in a file operation.
This error means mysql does not have the access rights to
the directory.
File name /var/lib/mysql/ibdata1
File operation call: 'open'.
所有文件的所有者/组是 mysql。我什至尝试将权限更改为a+rw。我可以 su 到 mysql 用户并使用 head 访问 ibdata1 文件。
解决方案:
问题是启用了selinux,导致新文件无法被访问。
I'm trying make a copy of a MySQL database on another server. I stop the server, tar up the mysql directory, copy it to the other server and untar it. I set all the permissions to match to the working server, and copied the my.cnf file so everything is the same except for server specific changes.
However, when I try to startup the server, I get the following InnoDB error:
InnoDB: Operating system error number 13 in a file operation.
This error means mysql does not have the access rights to
the directory.
File name /var/lib/mysql/ibdata1
File operation call: 'open'.
The owner/group for all the files is mysql. I even tried changing permissions to a+rw. I can su to the mysql user and access the ibdata1 file using head.
SOLUTION:
The problem was selinux was enabled and preventing the new files from being accessed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个愚蠢的问题,但人们忘记了:你说你检查了所有文件是否具有相同的权限;尽管如此,即使消息中这么说,您是否可能忘记检查包含目录的权限??
更新:另外两个建议:
您可以尝试插入
--console
和--log-warnings
标志,以获得大量调试输出,像这样(在我的 Mac 上):/usr/libexec/mysqld --console --log-warnings --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld /mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock
如果全部否则失败,您可以尝试 strace mysqld ... 来看看它到底失败了。错误将出现在底部的某个地方。
更新2:确实有趣......我看不到你的操作系统是什么。我通常不使用
/sbin/service
,它对我来说有点神秘;在 Mac 上,它已被弃用,取而代之的是launchctl
以及/System/Library/LaunchDaemons/mysqld.plist
中的配置文件,并且在大多数 Linux 机器上,您都有/ etc/init.d/mysqld
。所以你可以在那里插入 strace 。或者(未经测试,但联机帮助页表明这是可能的)您可以尝试跟踪服务调用:
这应该会生成文件
straces.pid
,其中之一应该是 mysqld 的,希望您能在那里找到错误。A silly question, but people forget: you said you checked that all files have the same permissions; still, even though it said so in the message, might you possibly have forgotten to check the permissions on the containing directory?
UPDATE: Two more suggestions:
You might try inserting
--console
and--log-warnings
flags, for lots of debugging output, something like this (on my Mac):/usr/libexec/mysqld --console --log-warnings --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock
If all else fails, you can probably try
strace mysqld ...
to see what exactly is it failing. The error will be somewhere at the bottom.UPDATE2: Interesting indeed... I can't see what your OS is. I normally don't use
/sbin/service
, it's a bit mysterious for me; on a Mac, it's deprecated in favour oflaunchctl
with config file in/System/Library/LaunchDaemons/mysqld.plist
, and on most Linux boxes you have/etc/init.d/mysqld
. So you could insert strace there.Or (untested, but manpage suggests it's possible) you could try stracing the service call:
This should produce files
straces.pid
, one of which should be mysqld's, and hopefully you'll find your error there.这不是对您的问题的直接答案,但我建议您尝试使用这些程序之一来满足您的备份/恢复需求。
Percona Xtrabackup:https://launchpad.net/percona-xtrabackup
Mydumper: http://www.mydumper.org/
两者都是很棒的工具,都是免费和开源的,并且将帮助您完全避免这个问题。
希望有帮助。
This isn't a direct answer to your question, but I would recommend trying one of these programs for your backup / restore needs.
Percona Xtrabackup: https://launchpad.net/percona-xtrabackup
Mydumper: http://www.mydumper.org/
Both are great tools, are free and open source, and will help you avoid that problem entirely.
Hope that helps.