mysql80 遇到 1130 Host ‘localhost‘ is not allowed to connect to this MySQL server

mysql80 遇到 1130 Host ‘localhost’ is not allowed to connect to this MySQL server

参考:Mysql 8.0.13忘记密码 重置密码

问题产生的原因:期望局域网同事能访问自己本地的mysql库表

做了如下操作:

  1. select host, user, pligin from user; 查看了系统mysql库-user表的加密规则,默认为:在这里插入图片描述
  2. update user set plugin='mysql_native_password'; FLUSH PRIVILEGES; 修改了所有的规则为mysql_native_password,并刷新MySQL的系统权限相关表,
  3. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION; 开放权限
  4. 同事仍连不上我的库,显示我这边不允许连接,怀疑是我本地没开远程权限,重启了mysql。
  5. 出现问题:Host 'localhost' is not allowed to connect to this MySQL server ,我自己都连不上本地的mysql。

问题解决步骤:

  1. 停止mysql服务service mysql stop or other method
  2. 绕过密码自己访问数据库,cmd 在安装路径中运行 mysqld --console --skip-grant-tables --shared-memory,此时会停在这里
  3. 新开cmd 输入登录命令:mysql -u root -p,输入密码处直接回车
  4. 还原mysql-user表中的加密规则
use mysql
update user set authentication_string=''where user='root';
  1. 清除登录密码,quit-mysql,关闭momom
use mysql;
update user set plugin='caching_sha2_password';
quit;
  1. 关闭以-console --skip-grant-tables --shared-memory启动的MySQL服务
  2. 密码已经置空,所以无密码状态登录MySQL,输入登录命令:mysql -u root -p,输入密码处直接回车
  3. 设置新密码,quit-mysql,无密码登录后,修改密码:
    ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '新密码';
    说什么0 row生效??what,查user发现对应的host是%,然后这样
    ALTER USER 'root'@'%' IDENTIFIED WITH caching_sha2_password BY '新密码';
  4. 使用新密码登录。mysql -uroot -p****
  5. bingo
    bingo。。。

ubuntu 忘记密码-调整办法

参考:ubuntu下MySQL忘记密码重置方法

  1. vim /etc/mysql/mysql.conf.d/mysqld.cnf

  2. add new line skip-grant-tables

  3. service mysql restart

  4. enter mysql in terminal mysql

  5. change to mysql use mysql;

  6. modify pswd update user set authentication_string='' where user='root';

    • 可通过 select user, host from mysql.user; 查询 user和host,便于精准修改。
    • update user set authentication_string='' where user='root' and host='%';
    • quit;
  7. vim /etc/mysql/mysql.conf.d/mysqld.cnf

  8. 注释掉 skip-grant-tables

  9. 重启mysql服务 service mysql restart

  10. mysql > use mysql修改新密码, ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '000000';

    • 可通过 select user, host from mysql.user; 查询 user和host,便于精准修改。
    • ALTER USER 'root'@'%' IDENTIFIED WITH caching_sha2_password BY '000000';
    • quit;
  11. bingo
    bingo。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值