• 需求:昨天决定转到团队的服务器开发,但是因为以前不是我配置的,所以重启服务器之后,mysql这个服务就丢失了,怎么也没法启动,昨天下午,个人的服务器又崩了,所以这个问题现在才做好,记录仪下
  • 找不到mysqld服务
    具体命令
service mysqld status
systemctl status mysqld

结果

Unit mysqld.service could not be found.

根据报错结果以及自上网搜发现是/etc/init.d不存在mysqld这个命令

  • 具体解决
  1. 找到mysql.server文件,这个文件据说与mysqld文件一模一样,只是文件名不同
[root@ldy ~]$ find / -name mysql.server
/usr/local/mysql-8.0.13/support-files/mysql.server

  1. 复制 mysql.server文件到/etc/init.d/目录下,重命名为mysqld
[root@ldy ~]$ cp /usr/local/mysql-8.0.13/support-files/mysql.server /etc/init.d/mysqld

  1. 查看mysqld status状态
[root@ldy ~]$ service mysqld status
/etc/init.d/mysqld: line 239: my_print_defaults: command not found

报了上面这个错
我不死心,事了下启动
4. 启动Mysqld,查看错误

[root@ldy ~]$ service mysqld start
/etc/init.d/mysqld: line 239: my_print_defaults: command not found
/etc/init.d/mysqld: line 259: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)

这次我发现都是在mysqld这个命令里面的错误,而且我至少知道,mysql安装路径不是这个

 /usr/local/mysql

而是这个

[lidengyin@ldy ~]$ cd /usr/local/mysql-8.0.13/
[lidengyin@ldy mysql-8.0.13]$ pwd
/usr/local/mysql-8.0.13

  1. 进入mysqld尝试修改基本路径
[root@ldy etc]$ vim -n /etc/init.d/mysqld 

具体修改报错路径为正确路径
报错路径

 66   basedir=/usr/local/mysql
 67   bindir=/usr/local/mysql/bin
 68   if test -z "$datadir"
 69   then
 70     datadir=/usr/local/mysql/data
 71   fi
 72   sbindir=/usr/local/mysql/bin
 73   libexecdir=/usr/local/mysql/bin

改正路径

 66   basedir=/usr/local/mysql-8.0.13
 67   bindir=/usr/local/mysql-8.0.13/bin
 68   if test -z "$datadir"
 69   then
 70     datadir=/usr/local/mysql-8.0.13/data
 71   fi
 72   sbindir=/usr/local/mysql-8.0.13/bin
 73   libexecdir=/usr/local/mysql-8.0.13/bin

  1. 再次查看状态并进行启动
[root@ldy etc]$ service mysqld status
 ERROR! MySQL is not running
[root@ldy etc]$ service mysqld start
Starting MySQL.Logging to '/usr/local/mysql-8.0.13/data/izwz9f5dsyzzjf3wit8o3cz.err'.
... SUCCESS! 

7. 进入mysql与报错

[root@ldy etc]$ mysql -uroot -p
-bash: mysql: command not found

没有找到命令,改用绝对路径


[root@ldy etc]$ /usr/local/mysql-8.0.13/bin/mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit

成功
8. 增加环境变量添加软链接
系统默认会查找/usr/bin下的命令,如果该目录下不存在此命令,我们需要做一个映射到/usr/bin目录下,相当于建立链接文件

[root@ldy etc]$ ln -s /usr/local/mysql-8.0.13/bin/mysql /usr/bin
[root@ldy etc]$ whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql
[root@ldy etc]$ ln -s /usr/local/mysql-8.0.13/bin/mysql /usr/local/bin
[root@ldy etc]$ whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/local/bin/mysql

输入mysql会报错

[root@ldy etc]$ mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@ldy etc]$ mysql -version
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

但是已经可以成功登陆了

[root@ldy etc]$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit
Bye
  1. 解决 Access denied for user ‘root’@‘localhost’ (using password: YES)问题
    这个难到我了my.ini我这应该不用该,因为我可以通过
mysql -uroot -p

成功进入,只是单独的mysql命令失败,有谁知道欢迎留言。

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐