出现这两种情况解决方案:
1.输入:whereis my 进行查找
找到之后:输入 vi /etc/my.cnf进入编辑
2.在最后面加上 skip-grant-tables 跳过验证登录
保存 shift+; wq systemctl restart mysqld重启数据库
3.如果开了mysql服务,关了(systemctl stop mysqld)重新开启(systemctl start mysqld),就可以直接登录mysql,输入密码时直接回车。
4.登陆之后输入use mysql
进行更新root的密码
update user set authentication_string=password(“root”) where User=“root”;
成功之后 ctrl+z退出
6.重启mysql服务 systemctl restart mysqld ,执行1步骤,去把之前添加的注释掉(前面使用#进行注释)然后保存 。
7.开启服务systemctl start mysqld, 直接输入账号和密码