旧硬盘系统的MySQL DataDir无法启动

mysql datadir from old hard drive system does not boot

提问人:togarha 提问时间:6/26/2017 更新时间:6/28/2017 访问量:141

问:

我正在尝试将 mysql 数据库从装有 fedora9(不再启动)的旧驱动器迁移到 ubuntu 16.04 服务器。

我将 /var/lib/mysql 文件夹从旧系统复制到新系统中的 /testdb/mysql。

我将所有者更改为 mysql:mysql 到新文件夹,并将 my.conf 的 datadir 更新到这个新文件夹,但 mysql 服务器不再启动。我收到以下错误:

170625 12:44:37 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
170625 12:44:37 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist
170625 12:44:37 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
170625 12:44:37 InnoDB: The InnoDB memory heap is disabled
170625 12:44:37 InnoDB: Mutexes and rw_locks use GCC atomic builtins
170625 12:44:37 InnoDB: Compressed tables use zlib 1.2.8
170625 12:44:37 InnoDB: Using Linux native AIO
170625 12:44:37 InnoDB: Initializing buffer pool, size = 128.0M
170625 12:44:37 InnoDB: Completed initialization of buffer pool
170625 12:44:37  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.
170625 12:44:38 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
170625 12:44:38 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist
170625 12:44:38 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
170625 12:44:38 InnoDB: The InnoDB memory heap is disabled
170625 12:44:38 InnoDB: Mutexes and rw_locks use GCC atomic builtins
170625 12:44:38 InnoDB: Compressed tables use zlib 1.2.8
170625 12:44:38 InnoDB: Using Linux native AIO
170625 12:44:38 InnoDB: Initializing buffer pool, size = 128.0M
170625 12:44:38 InnoDB: Completed initialization of buffer pool
170625 12:44:38  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.
170625 12:44:38 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
170625 12:44:38 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist
170625 12:44:38 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
170625 12:44:38 InnoDB: The InnoDB memory heap is disabled
170625 12:44:38 InnoDB: Mutexes and rw_locks use GCC atomic builtins
170625 12:44:38 InnoDB: Compressed tables use zlib 1.2.8
170625 12:44:38 InnoDB: Using Linux native AIO
170625 12:44:38 InnoDB: Initializing buffer pool, size = 128.0M
170625 12:44:38 InnoDB: Completed initialization of buffer pool
170625 12:44:38  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.

我尝试将所有权限,甚至 777 更改为所有文件(只是为了尝试),但总是有相同的结果。

如何恢复数据库?

mysql linux ubuntu 软呢帽

评论

0赞 togarha 6/26/2017
@BK435 正如我提出的问题,复制文件夹后的第一步是将所有者更改为 mysql:mysql (sudo chown -R mysql:mysql /testdb/mysql)。由于第一个更改不起作用,我尝试将所有权限更改为 777(将 mysql 保留为用户和组)
0赞 togarha 6/27/2017
这里是 ibdata 文件的用户和权限:-rwxrwxrwx 1 mysql mysql 18874368 jun 25 12:22 ibdata1
0赞 togarha 6/28/2017
新测试,我的默认文件夹在测试数据库上工作正常,然后我创建了一个以用户和组为文件夹的新文件夹,然后我将文件夹 mysql 复制到这个新文件夹(保留用户、组和权限),我将 my.cnf 中的 datadir 目录从 然后 mysql 不再启动(然后, 我想文件夹被正确更改了,但有些东西失败了)/var/lib/mysqlsudo mkdir /var/livroot:root/var/libsudo cp -rp /var/lib/mysql /var/liv/etc/mysql/my.cnfdatadir = /var/liv/mysql
0赞 togarha 6/28/2017
我真的不知道为什么会这样,但我找到了一种方法来恢复所有表,我会回答我自己的问题,将其标记为已解决,然后可以帮助某人

答:

0赞 togarha 6/28/2017 #1

我终于找到了恢复表的方法,它没有从 my.conf 更改 datadir(它不起作用,即使复制了工作正常的默认数据库的内容),我将要恢复的文件夹复制到默认 datadir,覆盖除 mysql.sock 和 mysql 文件夹之外的所有文件。 然后我启动了mysql服务器,它可以工作,但是有些表需要修复

mysqlcheck --repair --all-databases -u root -p 

现在一切正常