美文网首页
MySQL 重置 root 密码和允许远程访问

MySQL 重置 root 密码和允许远程访问

作者: 舌尖上的大胖 | 来源:发表于2018-09-19 16:58 被阅读0次

一、步骤

  1. 修改 MySQL 的登录设置:
vi /etc/my.cnf

[mysqld] 的段中加上一句:skip-grant-tables,保存并且退出 vi。

[mysqld]
skip-grant-tables
  1. 重新启动 mysqld
/etc/init.d/mysqld restart
或 service mysqld restart
  1. 登录
mysql -u root -p your-password

修改 MySQL 的 root 密码

mysql> USE mysql;
mysql> update mysql.user set authentication_string=password('new-password') where user='root';
# 查看用户信息
select host, user from user;
# 解决 root 不能远程登录的问题
mysql> update user set host = '%' where user = 'root';
mysql> flush privileges;
mysql> quit
  1. 将 MySQL 的登录设置修改回来
vi /etc/my.cnf 

将刚才在 [mysqld] 的段中加上的 skip-grant-tables 删除

[mysqld]
# skip-grant-tables

保存并且退出 vi。

  1. 重新启动 mysqld
/etc/init.d/mysqld restart
或 service mysqld restart

二、参考资料

(完)

相关文章

网友评论

      本文标题:MySQL 重置 root 密码和允许远程访问

      本文链接:https://www.haomeiwen.com/subject/ofginftx.html