GoodbyeYouth

一、编辑 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

分类:

技术点:

相关文章:

  • 2021-11-20
  • 2021-11-04
  • 2021-11-05
  • 2021-11-20
  • 2022-02-13
  • 2022-12-23
猜你喜欢
  • 2021-11-20
  • 2021-11-30
  • 2021-11-20
  • 2021-11-20
  • 2021-11-20
  • 2021-05-01
  • 2021-09-13
相关资源
相似解决方案