我有一个安装了 RHEL 7 的 AWS EC2mysql-5.5
实例xvda
。它datadir
在下面/var/lib/mysql
(默认情况下)。
我正在从版本 5.5.29 的数据库中导入转储,当前安装的版本是 5.5.60
由于空间不足xvdf
并将其安装在/data_drive
然后按照以下步骤更改数据目录:
- 停止
mysqld
并验证它是否已停止 - 用于
rsync -av /var/lib/mysql /data_drive
移动具有权限的文件夹 - 将旧的 mysql 数据目录移动到
xvda
(原始卷)上的备份文件 编辑
/etc/my.cnf
以更改[mysqld]
块以反映两者中的新datadir
位置socket
datadir=/data_drive/mysql socket=/data_drive/mysql/mysql.sock
在文件末尾添加了客户端块
[client] port=3306 socket=/data_drive/mysql/mysql.sock
- 保存文件,然后尝试以
mysqld
root 用户和非 root 用户身份重新启动服务,但它不会启动。
以下是/var/log/mysqld.log
相关时间戳的输出:
180713 19:27:57 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
180713 20:20:37 mysqld_safe Logging to '/var/log/mysqld.log'.
180713 20:20:37 mysqld_safe Starting mysqld daemon with databases from /data_drive/mysql
180713 20:20:37 [Warning] Can't create test file /data_drive/mysql/ip-10-0-0-180.lower-test
180713 20:20:37 [Note] /usr/sbin/mysqld (mysqld 5.5.60) starting as process 18669 ...
180713 20:20:37 [Warning] Can't create test file /data_drive/mysql/ip-10-0-0-180.lower-test
180713 20:20:37 [Warning] Can't create test file /data_drive/mysql/ip-10-0-0-180.lower-test
180713 20:20:37 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
180713 20:20:37 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
180713 20:20:37 InnoDB: The InnoDB memory heap is disabled
180713 20:20:37 InnoDB: Mutexes and rw_locks use GCC atomic builtins
180713 20:20:37 InnoDB: Compressed tables use zlib 1.2.3
180713 20:20:37 InnoDB: Using Linux native AIO
180713 20:20:37 InnoDB: Initializing buffer pool, size = 128.0M
180713 20:20:37 InnoDB: Completed initialization of buffer pool
180713 20:20: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.
当我运行sudo mysql_upgrade
它时,它给出了以下输出:
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
Error: Failed while fetching Server version! Could be due to unauthorized access.
FATAL ERROR: Upgrade failed
这是当前/data_drive/mysql
目录的样子:
[ec2-user@ip-10-0-0-180 mysql]$ ls -al /data_drive/mysql/
total 5921812
drwxr-xr-x. 4 mysql mysql 4096 Jul 13 18:45 .
drwxr-xr-x. 5 ec2-user root 4096 Jul 13 18:46 ..
-rw-rw----. 1 mysql mysql 6053429248 Jul 13 18:45 ibdata1
-rw-rw----. 1 mysql mysql 5242880 Jul 13 18:45 ib_logfile0
-rw-rw----. 1 mysql mysql 5242880 Jul 13 18:35 ib_logfile1
drwx------. 2 mysql root 4096 Jul 12 19:42 mysql
drwx------. 2 mysql mysql 4096 Jul 12 19:42 performance_schema