mariadb 注册成系统服务
时间: 2023-10-13 20:10:02 浏览: 50
在 Linux 系统中,可以通过 systemd 来注册 MariaDB 服务,使其在系统启动时自动运行。下面是具体的步骤:
1. 编写服务文件
在 `/etc/systemd/system` 目录下创建一个名为 `mariadb.service` 的文件,文件内容如下:
```
[Unit]
Description=MariaDB database server
After=network.target
[Service]
Type=forking
User=mysql
Group=mysql
ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
[Install]
WantedBy=multi-user.target
```
其中,`Description` 表示服务的描述,`After` 指定服务依赖的服务,这里是网络服务;`Type` 表示服务运行的类型,这里是 `forking`,表示服务是以 fork 的方式运行的;`User` 和 `Group` 表示服务运行的用户和用户组;`ExecStart` 是服务启动命令,这里是启动 MariaDB 服务;`WantedBy` 指定服务的启动级别,这里是多用户模式。
2. 重新加载 systemd
执行以下命令重新加载 systemd:
```
systemctl daemon-reload
```
3. 启动服务
执行以下命令启动 MariaDB 服务:
```
systemctl start mariadb
```
4. 设置开机自启动
执行以下命令设置 MariaDB 服务开机自启动:
```
systemctl enable mariadb
```
现在,MariaDB 服务已经注册成系统服务,并且在系统启动时自动运行。可以通过以下命令来管理 MariaDB 服务:
启动服务:
```
systemctl start mariadb
```
停止服务:
```
systemctl stop mariadb
```
重启服务:
```
systemctl restart mariadb
```
查看服务状态:
```
systemctl status mariadb
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)