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

134次阅读
没有评论

共计 653 个字符,预计需要花费 2 分钟才能阅读完成。

在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;

提醒:本文发布于368天前,文中所关联的信息可能已发生改变,请知悉!

AD:【腾讯云服务器大降价】2核4G 222元/3年 1核2G 38元/年
正文完
 
阿蛮君
版权声明:本站原创文章,由 阿蛮君 2023-03-27发表,共计653字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
Copyright © 2022-2024 阿蛮君博客 湘ICP备2023001393号
本网站由 亿信互联 提供云计算服务 | 无忧云 提供安全防护和加速服务