CentOS下MySQL开机自启动服务
CentOS 6
使用chkconfig 命令设置自启动服务,chkconfig命令主要用来更新、启动、停止、查询系统服务在不同运行等级的状态。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。
语法:
1 2 | chkconfig [--add][--del][--list] [系统服务] chkconfig [--level <运行级别>] [系统服务] [on/off/reset] |
参数:
1 2 3 4 5 6 7 8 9 10 11 | --add 增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据。 --del 删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据。 --list 显示所有系统服务在不同运行级别的状态信息。如果指定了服务名,那么只显示指定的服务在不同运行级的状态 --level<等级代号>[on/off/reset] 指定系统服务要在哪一个执行等级中开启或关毕。 0表示:表示关机 1表示:单用户模式 2表示:无网络连接的多用户命令行模式 3表示:有网络连接的多用户命令行模式 4表示:不可用 5表示:带图形界面的多用户模式 6表示:重新启动 |
设置mysql开机自启动:
1 2 3 4 5 6 7 | cd /usr/ local /mysql cp support-files/mysql.server /etc/init.d/mysql.server chkconfig mysql.server on #设定mysqld在运行定级2、3、4、5下为 on chkconfig --level 35 mysql.server on #设定mysqld在运行等级3、5为开启状态 chkconfig --list mysql.server #列出mysqld服务状态 chkconfig --list #列出所有的系统服务状态 |
CentOS 7
使用systemctl命令设置自启动服务:
1 2 | cd /usr/lib/systemd/system touch mysqld.service |
编辑内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | vim mysqld.service # Copyright (c) 2015, 2016, Oracle and / or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and / or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not , write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # systemd service file for MySQL forking server # [Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After =network.target After =syslog.target [Install] WantedBy=multi- user .target [Service] User =mysql Group =mysql Type=forking PIDFile=/usr/ local /mysql/run/mysqld.pid # Disable service start and stop timeout logic of systemd for mysqld service. TimeoutSec=0 # Execute pre and post scripts as root PermissionsStartOnly= true # Needed to create system tables #ExecStartPre=/usr/bin/mysqld_pre_systemd # Start main service ExecStart=/usr/ local /mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/run/mysqld.pid $MYSQLD_OPTS # Use this to switch malloc implementation EnvironmentFile=-/etc/sysconfig/mysql # Sets open_files_limit LimitNOFILE = 65535 Restart= on -failure RestartPreventExitStatus=1 PrivateTmp= false |
加载
1 2 3 | systemctl daemon-reload systemctl enable mysqld.service systemctl is -enabled mysqld |
启动服务:systemctl start xxx.service
关闭服务:systemctl stop xxx.service
重启服务:systemctl restart xxx.service
显示服务的状态:systemctl status xxx.service
在开机时启用服务:systemctl enable xxx.service
在开机时禁用服务:systemctl disable xxx.service
查看服务是否开机启动:systemctl is-enabled xxx.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律