Mariadb fails on setting data directory location - mysql

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

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)

Error:mysqld.service: Start request repeated too quickly. On manjaro

Yesterday I updated my manjaro. I had many problems since then.
Firstly, I type
systemctl status mysqld.service
to start MySQL, but it errors out with
mysqld.service: Start request repeated too quickly.
I has found many suggestions but they doesn't work.
I already have tried:
Check the permission of the MySQL data directory using the below command. The ownership should be mysql:mysql and the directory permission should be 700.
ls -ld /var/lib/mysql/
Check the permission of databases inside the MySQL data directory using the below command. The ownership should be mysql:mysql for all the files inside that directory.
ls -lh /var/lib/mysql/
Check the listening network TCP ports using the command
netstat -ntlp
Check the MySQL log files for any error using:
cat /var/log/mysql/mysqld.log
Try to start MySQL using
mysqld_safe --defaults-file=/etc/my.cf
My Error:
dong#dong-manjaro  /home/dong   systemctl status mysqld.service  13:30:33
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2019-08-22 13:30:29 CST; 6s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 8006 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Process: 8027 ExecStart=/usr/bin/mysqld $MYSQLD_OPTS (code=exited, status=127)
Main PID: 8027 (code=exited, status=127)
8月 22 13:30:29 dong-manjaro systemd[1]: mysqld.service: Service RestartSec=100ms expired, scheduling restart.
8月 22 13:30:29 dong-manjaro systemd[1]: mysqld.service: Scheduled restart job, restart counter is at 5.
8月 22 13:30:29 dong-manjaro systemd[1]: Stopped MySQL Server.
8月 22 13:30:29 dong-manjaro systemd[1]: **mysqld.service: Start request repeated too quickly.**
8月 22 13:30:29 dong-manjaro systemd[1]: **mysqld.service: Failed with result 'exit-code'.**
8月 22 13:30:29 dong-manjaro systemd[1]: **Failed to start MySQL Server.**
I have faced same issue and solved this problem like that:
if /var/log/mysql folder not exists:
sudo mkdir /var/log/mysql
and then give permission this folder:
sudo chown -R mysql:mysql /var/log/mysql
sudo systemctl stop mysql
sudo systemctl start mysql
Ran into similar issue.Follow steps(Sql server Version: '8.0.22-0ubuntu0.20.04.3')
1. Edit file: mysqld.cnf under directory: /etc/mysql/mysql.conf.d
2. Ensure that below basic settings are made in file mysqld.cnf and save it.
# * Basic Settings
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
datadir = /var/lib/mysql
# setting for localhost
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
log_error = /var/log/mysql/error.log
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
max_binlog_size = 100M
3. Check error log files under directory: /var/log/mysql
4. Remove all log files: Cd /var/log/mysql $ sudo rm -R error*
5. Start mysql server: $ sudo systemctl start mysql.service
6. Check status of mysql server: $ sudo systemctl status mysql.service
For us, it was to chown the logfile:
[root#tree ~]# ls -alh /var/log/mysqld.log
-rw-r----- 1 root logs 8.3K Apr 20 02:17 /var/log/mysqld.log
[root#tree ~]# chown mysql: /var/log/mysqld.log
[root#tree ~]# systemctl start mysqld
[root#tree ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-04-20 15:32:01 UTC; 20s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 28339 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 28313 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 28342 (mysqld)
Memory: 43.3G
CGroup: /system.slice/mysqld.service
└─28342 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Got rid of the same failure.
I fixed like this:
sudo chown -R mysql:mysql /var/lib/mysql
sudo systemctl start mysql

MySQL can't connect Ubuntu

Can't connect to MySQL service. Below is the status output error I get when trying to start
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
ruan#master.danzlive.com:~$ systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: activating (start-post) since Tue 2018-10-30 11:59:35 SAST; 1s ago
Process: 1988 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 1998 (mysqld); Control PID: 1999 (mysql-systemd-s)
Tasks: 16 (limit: 19660)
Memory: 130.2M
CPU: 577ms
CGroup: /system.slice/mysql.service
├─1998 /usr/sbin/mysqld
└─control
├─1999 /bin/bash /usr/share/mysql/mysql-systemd-start post
└─2031 sleep 1
Oct 30 11:59:35 ip-197-101-38-62 systemd[1]: Starting MySQL Community Server...
ruan#master.danzlive.com:~$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I faced similar Issue in Ubuntu 18.04. I found the reason that - On last day I cleared Ubuntu using Stacer Application. This application removed mysql log folder at location
/var/log/
So next day while starting MySQL, got this error.
I created that folder again and given permissions.
mkdir /var/log/mysql
sudo chown mysql:mysql -R /var/log/mysql
Try to add the database-username using the -u parameter directly via commandline.
mysql -u root <database>

How to move directory /var/lib/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

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/