MySQL 8 & RHEL 7 - starting services automatically is failing - mysql

I'm trying to shutdown and startup a MySQL 8 installation gracefully on reboot.
I've enable the service with systemctl with the following command.
systemctl enable rh-mysql80-mysqld.service
After rebooting I check the status
root#localhost > systemctl status rh-mysql80-mysqld.service
● rh-mysql80-mysqld.service - MySQL 8.0 database server
Loaded: loaded (/usr/lib/systemd/system/rh-mysql80-mysqld.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2022-03-11 12:18:24 PST; 16min ago
Process: 1635 ExecStopPost=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-wait-stop (code=exited, status=0/SUCCESS)
Process: 1242 ExecStart=/opt/rh/rh-mysql80/root/usr/libexec/mysqld-scl-helper enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysqld --basedir=/opt/rh/rh-mysql80/root/usr (code=exited, status=1/FAILURE)
Process: 1165 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Process: 1098 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Process: 1059 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /usr/bin/scl_enabled rh-mysql80 (code=exited, status=0/SUCCESS)
Main PID: 1242 (code=exited, status=1/FAILURE)
Status: "Server startup in progress"
I see this in the mysqld.log
/var/log/mysql/mysqld.log
2022-03-11T20:18:24.356194Z 0 [ERROR] [MY-011811] [Server] Can't start server: can't check PID filepath: No such file or directory
After executing the following commands I am able to manually start the service
[root#localhost ~]# sudo mkdir -p /var/run/rh-mysql80-mysqld/
[root#localhost ~]# sudo chown mysql.mysql /var/run/rh-mysql80-mysqld/
[root#localhost ~]# systemctl status rh-mysql80-mysqld.service
● rh-mysql80-mysqld.service - MySQL 8.0 database server
Loaded: loaded (/usr/lib/systemd/system/rh-mysql80-mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2022-03-11 12:58:16 PST; 58s ago
Process: 1635 ExecStopPost=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-wait-stop (code=exited, status=0/SUCCESS)
Process: 14780 ExecStartPost=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
Process: 14678 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Process: 14647 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /opt/rh/rh-mysql80/root/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Process: 14641 ExecStartPre=/usr/bin/scl enable $RH_MYSQL80_SCLS_ENABLED -- /usr/bin/scl_enabled rh-mysql80 (code=exited, status=0/SUCCESS)
Main PID: 14721 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/rh-mysql80-mysqld.service
└─14721 /opt/rh/rh-mysql80/root/usr/libexec/mysqld --basedir=/opt/rh/rh-mysql80/root/usr
Mar 11 12:58:15 localhost systemd[1]: Starting MySQL 8.0 database server...
Mar 11 12:58:15 localhost scl[14647]: Socket file /var/lib/mysql/mysql.sock exists.
Mar 11 12:58:15 localhost scl[14647]: No process is using /var/lib/mysql/mysql.sock, which means it is a garbage, so it will be removed automatically.
Mar 11 12:58:16 localhost systemd[1]: Started MySQL 8.0 database server.
Can anyone tell me what needs to be done so that the service can successfully start on reboot without the manual intervention ?
OS Linux 3.10.0-1160.59.1.el7.x86_64 #1 SMP Wed Feb 16 12:17:35 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
UPDATE:
I think I found my problem.
While visiting google university I found other people had "fixed" the same or similar problem by creating a service to create the missing directory in /var/run. I tried this unsuccessfully for an hour or so.
I then stumbled across a MySQL bug report which sent me on a search to locate this file.
-rw-r--r-- 1 root root 44 Sep 16 05:05 /usr/lib/tmpfiles.d/rh-mysql80-mysqld.conf
The contents of this file
d /run/rh-mysql80-mysqld 0755 mysql mysql -
If this file exists, why is it not working. I took a look in /varlog/messages and found this:
Mar 11 15:43:03 systemd-tmpfiles: [/usr/lib/tmpfiles.d/rh-mysql80-mysqld.conf:1] Unknown group 'mysql'.
Mar 11 15:43:03 systemd: systemd-tmpfiles-setup.service: main process exited, code=exited, status=1/FAILURE
Mar 11 15:43:03 systemd: Unit systemd-tmpfiles-setup.service entered failed state.
Mar 11 15:43:03 systemd: systemd-tmpfiles-setup.service failed.
"mysql" wasnt in the /etc/group file (despite the groupadd command saying that it already existed) so I manually added it.
Made this change, rebooted.... and BOOM!!....Mysql started automatically!

Related

MariaDB server is down but I can still login with mysql client (?)

MariaDB 10.3.8, Ubuntu 18 LTS.
When I check for the database status, I see that MariaDB is down. But I can login using the mysql client command. Is something wrong? How could I debug this?
sudo service mariadb status
mariadb.service - MariaDB 10.3.8 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; disabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: failed (Result: timeout) since Wed 2019-02-13 08:43:11 IST; 1min 0s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Process: 3293 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=1/FAILURE)
Process: 3712 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: 3706 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 3693 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
Main PID: 3878 (mysqld)
Tasks: 13 (limit: 4915)
CGroup: /system.slice/mariadb.service
└─3878 /usr/sbin/mysqld
# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 2346 user_running_mariadb 31u IPv6 28910 0t0 TCP *:mysql (LISTEN)
ps uax | grep mysql
root 2049 0.0 0.0 4628 1812 ? S 08:40 0:00 /bin/sh /usr/bin/mysqld_safe
user_running_mariadb 2346 0.1 0.4 3005364 114444 ? Sl 08:40 0:02 /usr/sbin/mysqld --basedir=/usr --datadir=/my_db_files_dir --plugin-dir=/usr/lib/mysql/plugin --user=user_running_mariadb --skip-log-error --pid-file=/my_db_rundir/run/mysqld.pid --socket=/my_db_rundir/run/mysqld.sock --port=3306
#/my_db_rundir/run# ls -l
-rw-rw---- 1 user_running_mariadb group_running_mariadb 5 Feb 13 08:40 mysqld.pid
srwxrwxrwx 1 user_running_mariadb group_running_mariadb 0 Feb 13 08:40 mysqld.sock
#/my_db_rundir/run# cat mysqld.pid
2346
I can login:
mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 145
Server version: 10.3.8-MariaDB-1:10.3.8+maria~bionic-log mariadb.org
inary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input
tatement.
MariaDB [(none)]>
Additional outputs:
Error log:
2019-02-13 8:52:13 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
2019-02-13 8:52:13 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2019-02-13 8:52:13 0 [Note] InnoDB: Unable to open the first data file
2019-02-13 8:52:13 0 [ERROR] InnoDB: Operating system error number 11 in a file operation.
2019-02-13 8:52:13 0 [ERROR] InnoDB: Error number 11 means 'Resource temporarily unavailable'
journalctl -u mariadb.service
Feb 13 08:51:31 my_host systemd[1]: mariadb.service: Start operation timed out. Terminating.
Feb 13 08:52:13 my_host systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
Feb 13 08:52:13 my_host systemd[1]: mariadb.service: Failed with result 'timeout'.
Feb 13 08:52:13 my_host systemd[1]: Failed to start MariaDB 10.3.8 database server.
The service is timed out ('Result: timeout'), and the service has the systemd configuration SendSIGKILL=no, which means systemd has just let mysqld continue running.
Why it time out? take a look at journalctl -u mariadb.service.
I could fix the issue, however I'm not completely sure about the root cause and what really fixed the issue. Still, perhaps this information helps others facing the same issue.
Reinstalled MariaDB and upgraded to 10.3.12. This wasn't probably needed because I kept hitting the same issue after the upgrade.
After reboot, noticed that msyqld status showed as active while mariadb as inactive:
/ati/mariadb/logs# sudo service mysql status
Loaded: loaded (/etc/init.d/mysql; generated)
Active: active (running)
Docs: man:systemd-sysv-generator(8)
Process: 1650 ExecStart=/etc/init.d/mysql start (code=exited, status=0/SUCCESS)
Tasks: 39 (limit: 4915)
CGroup: /system.slice/mysql.service
─2003 /bin/sh /usr/bin/mysqld_safe
─2301 /usr/sbin/mysqld --basedir=/usr...
└─2302 logger -t mysqld -p daemon error
sudo service mariadb status
mariadb.service - MariaDB 10.3.12 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; disabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: inactive (dead)
In MariaDB web site, found the way of enabling mariadb service, with
systemctl enable mariadb
Now, it works again.

ERROR 2006 (HY000): MySQL server has gone away & conflict with max_allowed_packet

I wanted to import a sql dump
mysql -u username mydb < file.sql
And of course i get the classic ERROR 2006 (HY000) at line 1701: MySQL server has gone away message. No big deal i know that i need to increase the packet size. So i edit the /etc/mysql/mysql.cnf file and add the line max_allowed_packet=64M. But when i try to start the mysql server i get an error.
mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2019-01-21 16:27:47 CET; 15s ago
Process: 9151 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid (code=exited, status=1/FAILURE)
Process: 9112 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 27620 (code=exited, status=0/SUCCESS)
Jan 21 16:27:47 aleksandar-pc systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Jan 21 16:27:47 aleksandar-pc systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
Jan 21 16:27:47 aleksandar-pc systemd[1]: Stopped MySQL Community Server.
Jan 21 16:27:47 aleksandar-pc systemd[1]: mysql.service: Start request repeated too quickly.
Jan 21 16:27:47 aleksandar-pc systemd[1]: mysql.service: Failed with result 'exit-code'.
If i remove the code added for packets, the server can be started normally.
Can anyone help me with this, i really need to import this large db and don't know how to fix this mysql error.
Mysql verison: Ver 14.14 Distrib 5.7.25, for Linux (x86_64)
Linux: Ubuntu 18.04 LTS
Ok i forgot this [mysqld] above:
[mysqld]
max_allowed_packet=128M

Webmin MySQL Error on starting

Firstly, I must say that I have not used these tools in the past so linux commands are not familiar to me.
Backstory:
On my Webmin server, I have been trying to get a Drupal Installation to work. I changed a parameter on the MySQL module and now the MySQL will not start.
Current Situation:
When I click "Start MySQL Server" I receive the follow:
Failed to start database : Redirecting to /bin/systemctl start
mariadb.service Job for mariadb.service failed because the control
process exited with error code. See "systemctl status mariadb.service"
and "journalctl -xe" for details.
I've search around this, and most people recommend to reinstall MariaDB.
I connected to the server with putty to get some more information
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2017-08-01 16:29:00 UTC; 7min ago
Process: 22851 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=1/FAILURE)
Process: 22850 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS)
Process: 22823 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 22850 (code=exited, status=0/SUCCESS)
Aug 01 16:28:57 li172-89.members.linode.com systemd[1]: Starting MariaDB database server...
Aug 01 16:28:57 li172-89.members.linode.com mysqld_safe[22850]: 170801 16:28:57 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Aug 01 16:28:57 li172-89.members.linode.com mysqld_safe[22850]: 170801 16:28:57 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Aug 01 16:29:00 li172-89.members.linode.com systemd[1]: mariadb.service: control process exited, code=exited status=1
Aug 01 16:29:00 li172-89.members.linode.com systemd[1]: Failed to start MariaDB database server.
Aug 01 16:29:00 li172-89.members.linode.com systemd[1]: Unit mariadb.service entered failed state.
Aug 01 16:29:00 li172-89.members.linode.com systemd[1]: mariadb.service failed.
[root#li172-89 ~]#
I gather that this means Mariadb wont even start so I should probably reinstall it. I did try to simply use a defaul my.cnf but that didn't really do anything.
Ideally, I do not want to lose any of the databases I have.
What should I do? Should I reinstall Mariadb? Is there a suitable guide that lists the commands? Could I install Mariadb but to another folder?
What is the best course of action at this point?

mysql.service failed because the control process exited with error code

I've looked at the various solutions from other threads but can't possibly figure this out; and solutions I've found aren't applying here. I'm running Ubuntu 16.04 LTS and spun up a server a few days ago. The server has been running fine until it didn't. After taking 15 miniutes to shutdown, I have now booted and MySQL won't start:
systemctl1 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 Wed 2017-03-01 09:04:59 GMT; 18s ago
Process: 6969 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
Process: 6967 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 6969 (code=exited, status=1/FAILURE); : 6970 (mysql-systemd-s)
CGroup: /system.slice/mysql.service
└─control
├─6970 /bin/bash /usr/share/mysql/mysql-systemd-start post
└─7080 sleep 1
sudo journalctl -xe
Mar 01 09:08:31 dwight systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
/var/log/mysql/error.log.1 is showing no errors today (the day MySQL crashed) but has been logging up until yesterday. /var/log/mysql/error.log is empty.
Please can anyone advise on how to diagnose?
Try this:
sudo service mysql start

Cannot get mysql to start with --skip-grant-tables on ubuntu 16

I lost my mysql password and need to reset it.
I have already tried https://help.ubuntu.com/community/MysqlPasswordReset
With the following result
erik#Trantor:~$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
erik#Trantor:~$ sudo /usr/sbin/mysqld --skip-grant-tables &
[1] 21335
erik#Trantor:~$
[1]+ Exit 1 sudo /usr/sbin/mysqld --skip-grant-tables
erik#Trantor:~$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
erik#Trantor:~$
I did not use the skip-networking option as that has been indicated by another post to cause it's own trouble and I'm not worried about security at the moment. Through some checking, I found that the service is failing to actually start with that option.
erik#Trantor:~$ sudo service mysql status
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
Active: inactive (dead) since Sun 2016-11-06 10:41:56 EST; 3min 45s ago
Process: 20846 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=e
Process: 20845 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
Process: 20842 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exi
Main PID: 20845 (code=exited, status=0/SUCCESS)
Nov 06 10:35:01 Trantor systemd[1]: Starting MySQL Community Server...
Nov 06 10:35:02 Trantor systemd[1]: Started MySQL Community Server.
Nov 06 10:41:55 Trantor systemd[1]: Stopping MySQL Community Server...
Nov 06 10:41:56 Trantor systemd[1]: Stopped MySQL Community Server.
lines 1-12/12 (END)
I'm not sure how to get mysql to start with the -skip-grant-tables option at this point, and without my password, I'm dead in the water.
I have tried to remove and install mysql-server again.
Anyone know how I can get it to start with the flag, or where I should look next?