美文网首页
CentOS 7下mysql 8修改datadir之后提示权限问

CentOS 7下mysql 8修改datadir之后提示权限问

作者: fomin | 来源:发表于2020-06-14 23:05 被阅读0次

    背景

    之前默认安装mysql的时候安装在系统盘,生成binlog的时候导致系统盘空间不足,需要把mysql移动到其它盘。

    操作

    1、停止 MySQL 8.0 服务,使用下面的指令

    service mysqld stop
    

    2、将默认的数据目录移至目标位置

    mv /var/lib/mysql/ /home/
    

    3、建立软连接

    ln -s /home/mysql /var/lib/
    

    4、启动服务

    service mysqld start
    

    问题

    出现下面的错误

    [root@localhost /]# systemctl mysqld start
    Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
    [root@localhost /]# systemctl status mysqld.service
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
       Active: failed (Result: exit-code) since 日 2020-06-14 22:13:45 CST; 1min 16s ago
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
      Process: 19271 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
      Process: 19241 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
     Main PID: 19271 (code=exited, status=1/FAILURE)
       Status: "Server startup in progress"
        Error: 13 (权限不够)
    6月 14 22:13:43 localhost.localdomain systemd[1]: Starting MySQL Server...
    6月 14 22:13:45 localhost.localdomain systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
    6月 14 22:13:45 localhost.localdomain systemd[1]: Failed to start MySQL Server.
    6月 14 22:13:45 localhost.localdomain systemd[1]: Unit mysqld.service entered failed state.
    6月 14 22:13:45 localhost.localdomain systemd[1]: mysqld.service failed.
    

    尝试修改/home/mysql的文件权限

    chown -R mysql.mysql /home/mysql
    

    还是出现上面的错误

    解决

    需要将Selinux临时关闭才能启动成功:

    [root@localhost /]# setenforce 0 
    [root@localhost /]# systemctl start mysqld
    

    相关文章

      网友评论

          本文标题:CentOS 7下mysql 8修改datadir之后提示权限问

          本文链接:https://www.haomeiwen.com/subject/mmrqxktx.html