码迷,mamicode.com
首页 > 数据库 > 详细

Ubuntu 18.04 使用Systemd管理MySQL 5.6

时间:2018-10-18 22:01:45      阅读:636      评论:0      收藏:0      [点我收藏+]

标签:desktop   install   hang   ice   stat   simple   管理   this   miss   

 

 

转自:https://blog.csdn.net/skykingf/article/details/45225981

如何用Systemd管理 general 包安装的MySQL呢? 

首先看看yum安装的MySQL提供的Systemd管理脚本

$ cat /usr/lib/systemd/system/mysqld.service 
#
# Simple MySQL systemd service file
#
# systemd supports lots of fancy features, look here (and linked docs) for a full list: 
#   http://www.freedesktop.org/software/systemd/man/systemd.exec.html
#
# Note: this file ( /usr/lib/systemd/system/mysql.service )
# will be overwritten on package upgrade, please copy the file to 
#
#  /etc/systemd/system/mysql.service 
#  
# to make needed changes.
# 
# systemd-delta can be used to check differences between the two mysql.service files.
#
 
[Unit]
Description=MySQL Community Server
After=network.target
After=syslog.target
 
[Install]
WantedBy=multi-user.target
Alias=mysql.service
 
[Service]
User=mysql
Group=mysql
 
# Execute pre and post scripts as root
PermissionsStartOnly=true
 
# Needed to create system tables etc.
ExecStartPre=/usr/bin/mysql-systemd-start pre
 
# Start main service
ExecStart=/usr/bin/mysqld_safe
 
# Don‘t signal startup success before a ping works
ExecStartPost=/usr/bin/mysql-systemd-start post
 
# Give up if ping don‘t get an answer
TimeoutSec=600
 
Restart=always
PrivateTmp=false

适当修改 /lib/systemd/system/mysqld.service 如下:

After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
Alias=mysql.service
[Service]
User=mysql
Group=mysql
PermissionsStartOnly=true
ExecStart=/usr/local/mysql/bin/mysqld_safe
TimeoutSec=600
Restart=always
PrivateTmp=false

  然后

ln -s /lib/systemd/system/mysqld.service /etc/systemd/mysqld.service

ln -s /lib/systemd/system/mysqld.service /etc/systemd/mysqld.service

然后 使用 systemctl 设置 mysqld.service自动启动

systemctl enable mysqld.service

  查看是否设置成:

 技术分享图片

systemctl 常见用法:

开机启动:

systemctl enable ***.service

停止开机启动:

systemctl disable ***.service

启动/停止/重启服务:

systemctl start/stop/restart ***.service

查询服务状态:

systemctl status ***.service

列出系统服务,-t后用tab键可以关联出所有支持的unit类型

技术分享图片

查询某项服务是否active,以sshd.serice为例

systemctl is-active sshd.service

直接查看某项服务的配置文件,以mysqld.serice为例

 技术分享图片

查看环境变量

技术分享图片

 

Ubuntu 18.04 使用Systemd管理MySQL 5.6

标签:desktop   install   hang   ice   stat   simple   管理   this   miss   

原文地址:https://www.cnblogs.com/digdeep/p/9813090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!