CentOS 7 下 修改Mysql 5.7datadir的位置,无法启动的问题解决

前端之家收集整理的这篇文章主要介绍了CentOS 7 下 修改Mysql 5.7datadir的位置,无法启动的问题解决前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

CentOS 7 下MysqL 默认安装在/var/lib/MysqL目录下,但是随着存储数据的增多,所在的硬盘空间很快被占满,导致无法进行插入、建表等操作。

这时需要将MysqL数据存储文件夹移植到别的文件夹下,网上有很多教程,如http://www.cnblogs.com/5201351/p/4912614.html,是一篇很好的教程,但是在实际移植过程发现,只有MysqL的数据文件夹/var/lib/MysqL被改为其他目录,无论如何修改/etc/my.cnf配置中的datadir和socket参数,都无法移动MysqLd。

使用如下命令,启东MysqL

service 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.

如果使用如下命令查看

service MysqLd status

会得到如下错误信息

Redirecting to /bin/systemctl status MysqLd.service
MysqLd.service - MysqL Server
Loaded: loaded (/usr/lib/systemd/system/MysqLd.service; enabled; vendor preset: disabled)
Active: Failed (Result: start-limit) since Fri 2017-10-20 09:03:33 CST; 1min 11s ago
Docs: man:MysqLd(8)
http://dev.MysqL.com/doc/refman/en/using-systemd.html
Process: 5130 ExecStart=/usr/sbin/MysqLd --daemonize --pid-file=/var/run/MysqLd/MysqLd.pid $MysqLD_OPTS (code=exited,status=1/FAILURE)
Process: 5108 ExecStartPre=/usr/bin/MysqLd_pre_systemd (code=exited,status=0/SUCCESS)
Main PID: 15110 (code=exited,status=0/SUCCESS)


Oct 20 09:03:33 bigdata-6 systemd[1]: Failed to start MysqL Server.
Oct 20 09:03:33 bigdata-6 systemd[1]: Unit MysqLd.service entered Failed state.
Oct 20 09:03:33 bigdata-6 systemd[1]: MysqLd.service Failed.
Oct 20 09:03:33 bigdata-6 systemd[1]: MysqLd.service holdoff time over,scheduling restart.
Oct 20 09:03:33 bigdata-6 systemd[1]: start request repeated too quickly for MysqLd.service
Oct 20 09:03:33 bigdata-6 systemd[1]: Failed to start MysqL Server.
Oct 20 09:03:33 bigdata-6 systemd[1]: Unit MysqLd.service entered Failed state.
Oct 20 09:03:33 bigdata-6 systemd[1]: MysqLd.service Failed.


一开始总以为是配置的问题,后来仔细查看一下msyql的日志文件: /var/log/MysqLd.log

出现了几个Warning,说文件无法创建

120609 11:31:31 MysqLd_safe MysqLd from pid file /var/run/MysqLd/MysqLd.pid ended
120609 11:35:12 MysqLd_safe Starting MysqLd daemon with databases from /mnt/hgfs/MysqL_data
120609 11:35:13 [Warning] Can't create test file /home/MysqL_data/data.lower-test
120609 11:35:13 [Warning] Can't create test file /home/MysqL_data/data.lower-test
/usr/libexec/MysqLd: Can't change dir to '/home/MysqL_data/' (Errcode: 13)
120609 11:35:13 [ERROR] Aborting

120609 11:35:13 [Note] /usr/libexec/MysqLd: Shutdown complete

120609 11:35:13 MysqLd_safe MysqLd from pid file /var/run/MysqLd/MysqLd.pid ended


解决方案:

关闭MysqL: service MysqLd stop

1、编辑/etc/selinux/config 文件,将其中的SELINUX禁用,SELINUX=disabled,重新启动系统。

2、移动/var/lib/MysqL到你需要的文件夹,mv /varlib/MysqL /home/MysqLdata

3、在/var/lib下创建一个链接ln -s /home/MysqLdata MysqL (这种方法可以不用修改my.cnf配置)

4、启动MysqL: service MysqLd start



记录一下,

猜你在找的CentOS相关文章