MariaDB: Custom data directory: Always need to keep /var/lib/mysql directory

一世执手 提交于 2019-12-25 18:14:11

问题


I installed MariaDB server 13.0 on Centos 7.0, disabled SELinux. I started the MariaDB server successfully. After that, I want to custom my database data directory. So here are my steps:

  • step 1: backup /var/lib/mysql directory
  • step 2: copy to another place: cp -Rp /var/lib/mysql /disk1/mysql
  • step 3: modify datadir from my.cfg.d/server.cfg: datadir=/disk1/mysql

Then I stop and start again the MariaDB server using the following command:

sudo systemctl start mariadb

Everything runs successfully. I can create a new database, a new table and I see it changes the data in the new path. However, if I remove all directory /var/lib/MySQL. I cannot start my server anymore.

Here is the log when running command systemctl status mariadb.service

  • mariadb.service - MariaDB 10.3.16 database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled) Drop-In: /etc/systemd/system/mariadb.service.d -custom.conf, migrated-from-my.cnf-settings.conf Active: failed (Result: exit-code) since Fri 2019-06-28 11:55:59 +07; 4s ago Docs: man:mysqld(8) https://mariadb.com/kb/en/library/systemd/ Process: 23296 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=1/FAILURE) Process: 23281 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=/usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS) Process: 23277 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS) Main PID: 23296 (code=exited, status=1/FAILURE)
    Status: "MariaDB server is down"

My old database server, I can delete /var/lib/mysql. Please explain to me the reason why.


回答1:


I have checked mysql log. It has a line with content "cannot read file /var/lib/mysql/mysql.sock". That is my old directory. So I think I need to custom mysql.sock.

In /etc/my.cnf.d/server.cnf:

[mysqld]
datadir=/disk1/mysql/
socket=/disk1/mysql/mysql.sock

In /etc/my.cnf.d/client.cfg:

[client]
# we need to configure this. so when we type mysql -u user. mysql can look up socket's location.
socket=/disk1/mysql/mysql.sock

After that, I can run and connect successfully to my mysql instance. I don't know why there is no tutorial point out this point. But this is a way I used to fix my problem.



来源:https://stackoverflow.com/questions/56797063/mariadb-custom-data-directory-always-need-to-keep-var-lib-mysql-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!