This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
##
#
# MySQL and MariaDB socket-file/pid-file folder issues – how to fix
#
##
# ----------
# There are 2 possibilities to force creating a folder on ech boot.
# ----------
# ----------
#
# 1.) Add 'ExecStartPre' directive to systemd service file:
#
# ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld
#
# ----------
MYSQL_USER=mysql
SOCKET_DIR="/var/run/mysqld"
MYSQL_SERVICE_FILE="/root/mysql.service"
perl -i -n -p -e "s&^(PermissionsStartOnly=.*)&\1\n\nExecStartPre=/usr/bin/install -m 755 -o $MYSQL_USER -g root -d $SOCKET_DIR&" $MYSQL_SERVICE_FILE
# ----------
#
# 2.) Create file /etc/tmpfiles.d/mysql.conf file with content:
#
# # systemd tmpfile settings for mysql or mariadb
# d /var/run/mysqld 0755 mysql mysql -
#
# see also:
# https://www.ryadel.com/en/linux-mysql-mariadb-pid-file-folder-fix/
#
# ----------
# Force systemd to create such folder on each startup. We can easily do that following the steps below:
#
# - Create a new /etc/tmpfiles.d/mysql.conf file with content:
#
# # systemd tmpfile settings for mysql or mariadb
# d /var/run/mysqld 0755 mysql mysql -
#
cat <<EOF > /etc/tmpfiles.d/mysql.conf
# systemd tmpfile settings for mysql or mariadb
d /var/run/mysqld 0755 mysql mysql -
EOF