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


共计 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;

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

Tips:清朝云网络工作室

阅读剩余
THE END