MySQL -- 03 -- 配置MySQL开机自启
一、编辑 mysql.service 文件
- 
vim /lib/systemd/system/mysql.service [Unit] Description=The MySQL server After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/etc/init.d/mysql.server start ExecStop=/etc/init.d/mysql.server stop PrivateTmp=true [Install] WantedBy=multi-user.target
- 
:wq 
二、重新载入配置文件
- systemctl daemon-reload
三、设置为开机自启
- systemctl enable mysql.service
四、其他常用命令
- 
systemctl start mysql.service - 启动 MySQL 服务
 
- 
systemctl stop mysql.service - 关闭 MySQL 服务
 
- 
systemctl restart mysql.service - 重启 MySQL 服务
 
- 
systemctl reload mysql.service - 重新载入 MySQL 服务
 
- 
systemctl force-reload mysql.service - 强制重新载入 MySQL 服务
 
- 
systemctl status mysql.service - 查看当前 MySQL 服务状态
 
- 
systemctl enable mysql.service - 设置 MySQL 开机自启
 
- 
systemctl disable mysql.service - 禁用 MySQL 开机自启
 
- 
systemctl is-enabled mysql.service - 查看 MySQL 是否开机自启
 
- 
systemctl list-unit-files - 查看开机启动项
 
PS: 注意如果使用的是 MySQL8.0 的版本,在启动 MySQL 的过程中可能会报以下错误

这是因为 MySQL8.0 需要 GCC5.3+ 的版本,而当 GCC 升级后,相应的类库还是旧版本的,因此我们要将 GCC5.3+ 版本中的类库路径设置进环境变量中,不过这里会有一个很坑的地方
正常情况下,我们只需要在 /etc/profile 系统配置文件中添加 GCC5.3+ 版本的类库路径,然后重新载入配置文件即可,但是并没有生效
解决方法如下
在 /etc/init.d/mysql.server 配置文件中添加 GCC5.3+ 版本中的类库路径,然后就可以正常启动 MySQL 了
export LD_LIBRARY_PATH=/usr/local/gcc/lib64

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号