将 MySQL 数据库复制到另一台机器

发布于 2024-09-09 12:03:23 字数 536 浏览 3 评论 0原文

我正在尝试在另一台服务器上创建 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

很快妥协 2024-09-16 12:03:23

一个愚蠢的问题,但人们忘记了:你说你检查了所有文件是否具有相同的权限;尽管如此,即使消息中这么说,您是否可能忘记检查包含目录的权限?

更新:另外两个建议:

  1. 您可以尝试插入 --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

  2. 如果全部否则失败,您可以尝试 strace mysqld ... 来看看它到底失败了。错误将出现在底部的某个地方。

更新2:确实有趣......我看不到你的操作系统是什么。我通常不使用 /sbin/service,它对我来说有点神秘;在 Mac 上,它已被弃用,取而代之的是 launchctl 以及 /System/Library/LaunchDaemons/mysqld.plist 中的配置文件,并且在大多数 Linux 机器上,您都有 / etc/init.d/mysqld。所以你可以在那里插入 strace 。

或者(未经测试,但联机帮助页表明这是可能的)您可以尝试跟踪服务调用:

strace -ff -o straces /sbin/service start mysqld

这应该会生成文件 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:

  1. 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

  2. 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 of launchctl 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:

strace -ff -o straces /sbin/service start mysqld

This should produce files straces.pid, one of which should be mysqld's, and hopefully you'll find your error there.

浅浅 2024-09-16 12:03:23

这不是对您的问题的直接答案,但我建议您尝试使用这些程序之一来满足您的备份/恢复需求。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文