使用其他数据目录时,Mysql服务器无法正常工作

时间:2017-10-12 14:35:48

标签: mysql amazon-linux

我在亚马逊Linux AMI上运行了一个amazon ec2实例。我尝试使用以下配置文件(/home/ec2-user/data)在第二个卷(挂载在/etc/my.cnf)上移动mysql的数据目录,但是mysql无法启动:

[mysqld]
datadir=/home/ec2-user/data/mysql
socket=/home/ec2-user/data/mysql/mysql.sock
log-bin=/var/log/mysql/mariadb-bin
log-bin-index=/var/log/mysql/mariadb-bin.index
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
port=3306
socket=/home/ec2-user/data/mysql/mysql.sock

我在日志文件中收到这些错误消息:

2017-10-12 14:06:33 20082 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2017-10-12 14:06:33 20082 [ERROR] Can't start server : Bind on unix socket: Permission denied
2017-10-12 14:06:33 20082 [ERROR] Do you already have another mysqld server running on socket: /home/ec2-user/data/mysql/mysql.sock ?
2017-10-12 14:06:33 20082 [ERROR] Aborting

当我将配置文件设置回以前的设置(到数据文件夹的备份)时,一切正常:

[mysqld]
datadir=/var/lib/mysql.bak
socket=/var/lib/mysql.bak/mysql.sock

log-bin=/var/log/mysql/mariadb-bin
log-bin-index=/var/log/mysql/mariadb-bin.index
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
port=3306
socket=/var/lib/mysql.bak/mysql.sock

这个问题的原因是什么?我已经检查了新数据文件夹的权限,但这并没有改变任何内容。

1 个答案:

答案 0 :(得分:0)

运行此命令:

chgrp -R mysql /home/ec2-user/data/mysql
chown -R mysql /home/ec2-user/data/mysql

您可以尝试以下配置文件吗?

[mysqld]
datadir=/home/ec2-user/data/mysql
socket=/var/lib/mysql.bak/mysql.sock

log-bin=/var/log/mysql/mariadb-bin
log-bin-index=/var/log/mysql/mariadb-bin.index
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
port=3306
socket=/var/lib/mysql.bak/mysql.sock