在自动无人值守升级发生时管理 Ubuntu Lunix 16.4 上的 MySQL 设置

在自动无人值守升级发生时管理 Ubuntu Lunix 16.4 上的 MySQL 设置

我刚刚在无人值守模式下自动升级了 MySQL 5.7.25,我为 ExecStart 设置的设置消失了。
我该如何保留 ExecStart 设置,以免在下一次自动无人值守升级时出现盲区。

ExecStart 设置位于文件中:

lib/systemd/system/mysql.service:

# MySQL systemd service file

[Unit]
Description=MySQL Community Server
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
PermissionsStartOnly=true
ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
# Normally, we'd simply use:
# ExecStart=/usr/sbin/mysqld
ExecStart=/usr/sbin/mysqld --sql-mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
ExecStartPost=/usr/share/mysql/mysql-systemd-start post
TimeoutSec=600
Restart=on-failure
RuntimeDirectory=mysqld
RuntimeDirectoryMode=755

答案1

这是我在阅读以下帖子后发现的

https://askubuntu.com/questions/659267/how-do-i-override-or-configure-systemd-services

您需要对文件夹进行更改,以使其免受 Ubuntu Linux(尤其是 MySQL)上定期发生的自动无人值守升级的影响:

sudo systemctl edit mysql

这将带您进入编辑器,您需要输入以下内容:

[Service]

ExecStart=

ExecStart=/usr/sbin/mysqld --sql-mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

The first ExecStart clears whatever setting this variable had been set as.  The  next ExecStart will set up the variable with the proper option for starting mysql.    

After saving this, it will create a file called override.conf  in the folder mysql.service.d   i.e. in /etc/systemd/system/mysql.service.d





The file  /lib/systemd/system/mysql.service should look as follows:
 # MySQL systemd service file

[Unit]
Description=MySQL Community Server
After=network.target

[Install]
WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

PermissionsStartOnly=true

ExecStartPre=/usr/share/mysql/mysql-systemd-start pre

ExecStart=/usr/sbin/mysqld

ExecStartPost=/usr/share/mysql/mysql-systemd-start post

TimeoutSec=600

Restart=on-failure

RuntimeDirectory=mysqld

RuntimeDirectoryMode=755

您需要重新启动 MySQL 服务器,请执行以下操作:

sudo systemctl daemon-reload
sudo service mysql restart

相关内容