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
记录一下,