开发者

Copying a MySQL database to another machine

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开发者_JS百科 user and access the ibdata1 file using head.

SOLUTION:

The problem was selinux was enabled and preventing the new files from being accessed.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜