由于/
分区只有50G,并且我的数据比那更大。 /home
有500G空间。 所以,我把MySQL的所有数据移到/home
。 以下是我的步骤(在root
帐户下):
喊下MySQL
# mysql -u root -p shutdown
制作data
目录。
# cd /home/ && mkdir data
将/var/lib/mysql
目录移动到/home/data
# mv /var/lib/mysql /home/data/
编辑my.cnf
和/usr/lib64/mysql/mysql_config
将socket=/var/lib/mysql/mysql.sock
更改为socket=/home/data/mysql/mysql.sock
仅在my.cnf
[mysqldb]
部分添加datadir=/home/data/mysql
ln -s
首先我在/var/lib/
创build了一个名为mysql
的目录。 和chown mysql:mysql /var/lib/mysql
build立连接: ln -s /home/data/mysql/mysql.sock /var/lib/mysql/mysql.sock
更改/home/data/mysql
所有者
chown -R mysql:mysql /home/data/mysql/
启动MySQL服务
# systemctl start mariadb.service
但是,它开始失败。
[root@localhost]~# systemctl start mariadb.service Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
详细的信息是:
[root@localhost]~# systemctl status mariadb.service ● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since Thu 2016-04-21 19:51:13 HKT; 39s ago Process: 7144 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=1/FAILURE) Process: 7143 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS) Process: 7090 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS) Main PID: 7143 (code=exited, status=0/SUCCESS) Apr 21 19:51:12 localhost.localdomain systemd[1]: Starting MariaDB database server... Apr 21 19:51:12 localhost.localdomain mysqld_safe[7143]: 160421 19:51:12 mysqld_safe Logging to '/home/data/mysql/localhost.localdomain.err'. Apr 21 19:51:12 localhost.localdomain mysqld_safe[7143]: 160421 19:51:12 mysqld_safe Starting mysqld daemon with databases from /home/data/mysql Apr 21 19:51:12 localhost.localdomain mysqld_safe[7143]: 160421 19:51:12 mysqld_safe mysqld from pid file /home/data/mysql/localhost.localdomain.pid ended Apr 21 19:51:13 localhost.localdomain systemd[1]: mariadb.service: control process exited, code=exited status=1 Apr 21 19:51:13 localhost.localdomain systemd[1]: Failed to start MariaDB database server. Apr 21 19:51:13 localhost.localdomain systemd[1]: Unit mariadb.service entered failed state. Apr 21 19:51:13 localhost.localdomain systemd[1]: mariadb.service failed. [root@localhost]~# journalctl -xe -- The start-up result is done. Apr 21 19:50:01 localhost.localdomain systemd[1]: Starting Session 7 of user root. -- Subject: Unit session-7.scope has begun start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit session-7.scope has begun starting up. Apr 21 19:50:01 localhost.localdomain CROND[6971]: (root) CMD (/usr/lib64/sa/sa1 1 1) Apr 21 19:51:12 localhost.localdomain polkitd[900]: Registered Authentication Agent for unix-process:7084:268964 (system bus name :1.80 [/usr/bin/pkttyagent Apr 21 19:51:12 localhost.localdomain systemd[1]: Starting MariaDB database server... -- Subject: Unit mariadb.service has begun start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit mariadb.service has begun starting up. Apr 21 19:51:12 localhost.localdomain mysqld_safe[7143]: 160421 19:51:12 mysqld_safe Logging to '/home/data/mysql/localhost.localdomain.err'. Apr 21 19:51:12 localhost.localdomain mysqld_safe[7143]: 160421 19:51:12 mysqld_safe Starting mysqld daemon with databases from /home/data/mysql Apr 21 19:51:12 localhost.localdomain mysqld_safe[7143]: 160421 19:51:12 mysqld_safe mysqld from pid file /home/data/mysql/localhost.localdomain.pid ended Apr 21 19:51:13 localhost.localdomain systemd[1]: mariadb.service: control process exited, code=exited status=1 Apr 21 19:51:13 localhost.localdomain systemd[1]: Failed to start MariaDB database server. -- Subject: Unit mariadb.service has failed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit mariadb.service has failed. -- -- The result is failed. Apr 21 19:51:13 localhost.localdomain systemd[1]: Unit mariadb.service entered failed state. Apr 21 19:51:13 localhost.localdomain systemd[1]: mariadb.service failed. Apr 21 19:51:13 localhost.localdomain polkitd[900]: Unregistered Authentication Agent for unix-process:7084:268964 (system bus name :1.80, object path /org/f lines 3132-3161/3161 (END)
我的操作系统是CentOS 7
,MySQL是MariaDB
。
如何解决它? 谢谢!
当你尝试启动它时,注意你的/ var / log / messages。 您可能会发现SELinux阻碍:
tail -f /var/log/messages
尝试将MariaDB保留在预期的位置/ var / lib / mysql。 选项包括:
1)如果性能很重要:缩小/ home上的文件系统和分区(或逻辑卷),然后创build一个新分区并将其挂载到/ var / lib / mysql
2)如果性能不那么严重:在/home/mysql.img上创build一个大文件,并通过losetup使用该文件作为/ dev / loop0并挂载到/ var / lib / mysql。
3)如果性能真的没有关系:做一个大的稀疏文件,并通过“放弃”到你的ext4文件系统,以保持文件稀疏losetup。