Mysql 忘记密码以及开启远程登录

在Linux环境下找到配置文件,位置:/etc/my.cnf 。

service mysqld xxx #第一种
mysqld xxx   #第二种:在mysql的bin目录下执行

#停止 stop
#启动 start
#重启 restart

1、忘记密码

报错:Access denied for user 'root'@'localhost' (using password: YES)

首先修改配置文件,在 mysqld 下添加 skip-grant-tables

[client]
#password = your_password
port  = 3306

[mysqld]
skip-grant-tables

接下来在 mysql 的 bin 目录下执行mysql,然后执行以下命令

# 切换数据库
use mysql

# mysql 5.7
update user set authentication_string = password('123456') where user='root';
# mysql 5.5
update user set password = password('123456') where user='root';

# 刷新权限
flush privileges;
quit;

然后就可以登录了。

2、开启远程登录(关闭防火墙 3306)

报错:Host is not allowed to connect to this MySQL server

首先进入mysql

# 切换数据库
use mysql

# 更新语句
update user set host = '%' where user = 'root';

# 刷新权限
flush privileges;
quit;
AD: 【腾讯云服务器大降价】 2核4G 222元/3年 1核2G 38元/年
网站:阿蛮君博客
标题:Mysql 忘记密码以及开启远程登录
链接:https://www.amjun.com/1451.html
本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行核实删除。
转载本站文章需要遵守:商业转载请联系站长,非商业转载请注明出处!!
THE END
分享
二维码
打赏
海报
Mysql 忘记密码以及开启远程登录
在Linux环境下找到配置文件,位置:/etc/my.cnf 。 service mysqld xxx #第一种 mysqld xxx #第二种:在mysql的bin目录下执行 #停止 stop #启动 start #重……
<<上一篇
下一篇>>