Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
186 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...