How to move directory /var/lib/mysql - mysql

Archlinux, MariaDB 10.1.25
I have working mysql. Now I decided to move directory with data.
I tried to move /var/lib/mysql to /home/srv/mysql. And creat symlink to old path (/var/lib/mysql). But mysqld gives error:
Job for mariadb.service failed because the control process exited with error code.
See "systemctl status mariadb.service" and "journalctl -xe" for details.
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 Wed 2017-08-02 20:19:17 +10; 7min ago
Process: 29629 ExecStart=/usr/bin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=1/FAILURE)
Process: 29576 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=exite
Process: 29575 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Main PID: 29629 (code=exited, status=1/FAILURE)
Status: "MariaDB server is down"
Access rights are correct. User mysql, group mysql.
Tell me what I'm doing wrong.

Check your my.cnf file, there might be following option set:
symbolic-links = 0
I'm not sure though, if this fixes the problem.
I recommend fixing the issue in another way. Instead of using symbolic links, simply adjust the data dir in your my.cnf with
datadir = /home/srv/mysql

Related

how to exit a node from mysql clustering galera

I'm using galera mysql clustring.
I have 3 nodes on 3 virtual machines as master.
ubuntu server is running.
node 1 and node 2 is shutdown and I only access to node 3 with ssh.
now I want to run this mysql node as a remote mysql conneciton.
how to change this config?
systemctl status mariadb.service
● mariadb.service - MariaDB 10.3.35 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf, override.conf
Active: activating (start) since Sun 2022-11-27 21:06:06 +0330; 12h ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Process: 601851 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
Process: 601863 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 601866 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, st>
Main PID: 602158 (mysqld)
Status: "WSREP state transfer ongoing, current seqno: 1131170 waited 45541.000000 secs"
Tasks: 7 (limit: 48160)
Memory: 527.4M
CGroup: /system.slice/mariadb.service
└─602158 /usr/sbin/mysqld --wsrep_start_position=1f8146c8-1825-11ed-8421-47d88112f937:1131170
I got this error message:
WSREP state transfer ongoing, current seqno: 1131170 waited 45541.000000 secs
and mysql command:
mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

MySQL can't start after transfering from old to new server

I recently transferred mysql data from an old ssh server to a new ssh server using rsync, the transfer was from files in old server /var/lib/mysql/ to /var/lib/mysql/ in new server , the move was good. After that I tried to restart the mysql server using sudo service mysql restart.
I got this error :
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
I did a systemctl status mysql.service after and got this :
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2020-06-23 20:44:07 UTC; 1min 7s ago
Process: 16490 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=1/FAILURE)
Process: 16466 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 11702 (code=exited, status=0/SUCCESS)
So, I did some research and set ownership of the mysql using chown mysql:mysql -R /var/lib/mysql/ but it didn't make any difference.
I need some assistance to solve this issue. Is there perhaps something that I missed to do?
Thanks!

MySQL 5.7 Upgrade error on Ubuntu 16.04

I was just uninstalling nginx and then in that apt-get remove command, I see that mysql-server is updating. Then the update hung up. I killed the "apt-get" process (followed some answer somewhere). Then things kept on happening and the mysql was completely screwed up. I followed #jargonjunkie 's answer here: https://askubuntu.com/questions/763534/cannot-reinstall-mysql-server-after-its-purge also but to no avail.
(I have even removed /var/lib/mysql and /etc/mysql).
Here's what happens when I try to start mysql:
root#lamp-512mb-nyc1-01:~/etc/mysql# sudo /etc/init.d/mysql start
[....] Starting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
failed!
Here's what "systemctl status mysql.service" shows:
root#lamp-512mb-nyc1-01:~/etc/mysql# systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: activating (start-post) (Result: exit-code) since Tue 2017-10-24 13:40:38 UTC; 13s ago
Process: 21324 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
Process: 21315 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 21324 (code=exited, status=1/FAILURE); : 21325 (mysql-systemd-s)
Tasks: 2
Memory: 18.2M
CPU: 423ms
CGroup: /system.slice/mysql.service
└─control
├─21325 /bin/bash /usr/share/mysql/mysql-systemd-start post
└─21357 sleep 1
Oct 24 13:40:38 lamp-512mb-nyc1-01 systemd[1]: Starting MySQL Community Server...
Oct 24 13:40:38 lamp-512mb-nyc1-01 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
I have seen several questions related to mysql-server 5.7 upgrade on ubuntu, but couldn't find anything that worked.
Please help. Thanks in advance.
Save your data (/var/lib/mysql) and totally remove MySQL:
apt purge mysql* mariadb*
Remove files files from /var/lib/mysql, /etc/mysql, /lib/systemd/system/mysql.service, /usr/share/mysql
Install MySQL again
Check if it starts
Bring data back (if needed)
Check logs journalctl -xe

Mariadb fails on setting data directory location

Base OS: Centos 7 Atomic Host
I installed Mariadb 10.2 & changed the data directory to a folder under /home directory. I made the respective changes to /etc/my.cnf to point to the data directory & mysql socket. I also did the concerned changes in SE linux context.
Now, when I start the mariadb service by systemctl start mariadb it fails. The output to the system status mariadb.service is
Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
# systemctl status mariadb.service
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: failed (Result: exit-code) since Tue 2017-09-12 13:54:15 CEST; 23s ago
Process: 3099 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=1/FAILURE)
Process: 3066 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: 3063 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Main PID: 3099 (code=exited, status=1/FAILURE)
Status: "MariaDB server is down"
/etc/my.cnf is
[client-server]
[mysqld]
datadir=/home/data/db/mysql
socket=/home/data/db/mysql/mysql.sock
[client]
port=3306
socket=/home/data/db/mysql/mysql.sock
Any ideas on how to get MariaDB up & running?
Finally, I got the solution. The link below should help anyone stuck in similar problem. The 1st task is to do the usual procedure for changing data directory for mariadb & the 2nd task is to allow mariadb.service to use /home as the base directory for data storage.
Task 1:
Following by Gabriel Cánepa's advice at Tecmint.com:
1.1.Changing the default MySQL/MariaDB Data Directory
# mkdir /mnt/mysql-data
# chown -R mysql:mysql /mnt/mysql-data
1.2.Identify Current MySQL Data Directory
# mysql -u root -p -e "SELECT ##datadir;"
1.3.Copy MySQL Data Directory to a New Location
# systemctl stop mariadb
# systemctl is-active mariadb
# cp -R -p /var/lib/mysql/* /mnt/mysql-data
1.4.Configure a New MySQL Data Directory
# vi /etc/my.conf
[mysqld]:
datadir=/mnt/mysql-data
socket=/mnt/mysql-data/mysql.sock
[client]:
port=3306
socket=/mnt/mysql-data/mysql.sock
1.5.Set SELinux Security Context to Data Directory
# semanage fcontext -a -t mysqld_db_t "/mnt/mysql-data(/.*)?"
# restorecon -R /mnt/mysql-data
1.6.Restart mariadb.service after Task 2
# systemctl start mariadb
1.7.Verify the location
# mysql -u root -p -e "SELECT ##datadir;"
Task 2:
As suggested by Thomas:
To run MariaDB SQL from /home, in the file /usr/lib/systemd/system/mariadb.service, just change :
ProtectHome=true
to :
ProtectHome=false

Archlinux mysqld won't launch

Cat' launch mysqld on my archlinux x64.
Job for mysqld.service failed. See "systemctl status mysqld.service" and "journalctl -xe" for details.
after systemctl start mysqld
in log
mysqld.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: timeout) since Mon 2015-04-06 22:07:24 UTC; 9ms ago
Process: 18077 ExecStart=/usr/bin/mysqld --pid-file=/run/mysqld/mysqld.pid (code=exited, status=1/FAILURE)
Main PID: 18077 (code=exited, status=1/FAILURE)
CGroup: /system.slice/mysqld.service
`-control
Apr 06 22:07:24 atlas systemd[1]: Failed to start MariaDB database server.
Apr 06 22:07:24 atlas systemd[1]: Unit mysqld.service entered failed state.
Apr 06 22:07:24 atlas systemd[1]: mysqld.service failed.
What can i do? Thanks!
You will get detailed info in systemd journal: sudo journalctl -f then, on an other terminal, start mysql: sudo systemctl start mysqld to get logs on the first terminal. You will likely get error messages that will help you figure out what goes wrong.
You should type this command before starting the service
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
ِAnd later you can start the service Regularly
For one session:
systemctl start mysqld
OR being enabled automatically on startup << (NOT RECOMMENDED)
systemctl enable mysqld
Did you follow the install instruction on the ArchLinux Wiki ?
https://wiki.archlinux.org/index.php/MySQL#Installation
As mentionned by Medo Tareq, you need to run the following command :
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
(Obviously you can adjust the parameters on the command, if you know what you are doing.)
The Wiki page also has other hint and information, notably about the mysql_secure_installation command that "will interactively guide you through a number of recomended security measures at the database level".
Try change the permission of MySQL folder. If you are working locally and try to reinstall MySQL again after runing this command, it will work.
sudo chmod -R 755 /var/lib/mysql/