我有一个 EC2 实例,正在尝试将 mysql 数据目录从默认驱动器移动到另一个 EBS 卷。我将 mysql 目录移动/var/lib/mysql
到新目标,然后修改文件my.cnf
以将数据目录指向新位置。然后我尝试重新启动 mysql,我收到以下消息。
MySQL Daemon failed to start.
Starting mysqld: [FAILED]
我正在运行新 EC2 实例附带的 Linux 默认发行版。以下是文件my.cnf
和的详细信息mysqld.log
。对我可能做错的事情有什么建议吗?
我的cnf
[mysqld]
#datadir=/var/lib/mysql
datadir=/root/appfinder/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
设置文件夹的权限
chmod -R 777 /root/appfinder/mysql
mysqld.log
110616 18:37:53 mysqld_safe Starting mysqld daemon with databases from /root/appfinder/mysql
/usr/libexec/mysqld: Table 'plugin' is read only
110616 18:37:53 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
InnoDB: Log scan progressed past the checkpoint lsn 0 37356
110616 18:37:53 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 0 44233
110616 18:37:53 InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66$
InnoDB: Apply batch completed
110616 18:37:53 InnoDB: Started; log sequence number 0 44233
5110616 18:37:53 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'host' is read only
110616 18:37:53 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
答案1
我尝试将 EBS 卷重新安装到/myFolder
而不是/root/myFolder
。这似乎已解决权限问题。
答案2
/root/appfinder/mysql 主管必须是所有者 mysql。为此,chown mysql:mysql /root/appfinder/mysql 和 chown -R mysql:mysql /root/appfinder/mysql/。
mysql 的所有数据文件的所有者必须是 mysql。
答案3
我也遇到了类似的问题。
以下是我在 Ubuntu 12.04 Lts 上执行的步骤:
想要将数据文件从 /var/lib/mysql 移动到 /newdir_path/newdir
- sudo mysql 停止
- sudo rsync -av /var/lib/mysql /newdir_path/newdir
- sudo gedit /etc/mysql/my.cnf,将 datadir 更改为 /newdir_path/newdir
- sudo gedit /etc/apparmor.d/usr.sbin.mysqld,更改:
-
代替:
- /var/lib/mysql/r,
- /var/lib/mysql/** /rwk
- /newdir_path/newdir/ r,
- /newdir_path/newdir/** rwk,
- sudo /etc/init.d/apparmor 重启
- (!!!) sudo chown mysql:mysql/新目录路径
- sudo 启动 mysql