首页 > 技术文章 > mysql 解决忘记密码 mysql5.7 远程登录不上MySQL(解决腾讯服务器初始mysql密码问题)

liweiweicode 2019-11-22 20:20 原文

一、修改MySQL启动配置文件

#如果不知道配置文件,先查找
find / -name my.cnf
#编辑配置文件 vim
/etc/my.cnf

 

 

 

 在[mysql]  下面第一行加入 

 skip-grant-tables

 

重启mysql,以root用户登录

#重启
service mysqld restart
#登录
mysql -uroot -p
use mysql
update user set password=password('123') where user='root';

 

 然后报错了,这个是5.7版本下的mysql数据库下已经没有password

update mysql.user set authentication_string=password('*******') where user='*******';
#刷新权限
flush privileges

 

 

 

 然后,把配置文件里面加的内容去掉,重启数据库

参考博客: https://blog.csdn.net/baidu_34036884/article/details/80364285

       https://www.cnblogs.com/wangbaobao/p/7087032.html

 

二、数据库远程登录不了,是数据库做了限制本地登录,需要修改配置

参考博客:https://blog.csdn.net/hexu_blog/article/details/91046985

  1. 在装有MySQL的机器上登录MySQL mysql -u root -p密码
  2. 执行use mysql;
  3. 执行这一句执行完可能会报错,不用管它。
    update user set host = '%' where user = 'root';
  4. 执行FLUSH PRIVILEGES;

 

这时候,通过远程可以连接成功:

 

 

 

 

 

 

 

 

 

 

 

 

推荐阅读