-1

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.

Trần Kim Dự
  • 5,872
  • 12
  • 55
  • 107
  • Possible duplicate of [How to change MySQL data directory?](https://stackoverflow.com/questions/1795176/how-to-change-mysql-data-directory) – René Höhle Jun 27 '19 at 18:50
  • It is doesn't duplicate. I provide more detail about database version, OS version, my steps, and point out detail what point I cannot successfully. Please look again carefully. – Trần Kim Dự Jun 27 '19 at 18:56
  • So if you think that this was not my downvote ;) and there is only one place where you have to change the location and that is described in article. The other thing it that is is more a Server related question. So you should try it on ServerFault. – René Höhle Jun 27 '19 at 19:22
  • "Cannot start" -- any error in the logs? – Rick James Jun 27 '19 at 21:23
  • @RickJames I have fixed my problem by custom `mysql.sock` file path. I don't know why there is no tutorial discussing this. (and still successfully). Do you know why ? Thanks. – Trần Kim Dự Jun 28 '19 at 05:32

1 Answers1

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.

Trần Kim Dự
  • 5,872
  • 12
  • 55
  • 107