1、解决思路
mysqld 服务提供了允许免密登录的启动参数"–skip-grant-tables",使用此参数启动 mysqld 服务后,所有mysql用户均可免密登录 mysqld 服务器, 并且拥有对所有表的全部操作权限。
2、先停止mysqld服务
$ systemctl stop mysqld
3、修改my.cnf配置文件以开启免密登录
[mysqld]
# 开启免密登录
# --skip-grant-tables:Start without grant tables. This gives all users FULL ACCESS to all tables
skip-grant-tables=true
4、启动mysqld服务
$ systemctl start mysqld
5、免密登录mysqld并修改root用户密码
$ mysql -uroot
mysql> update mysql.user set authentication_string=password('新密码') where user='root' and Host ='localhost';
mysql> flush privileges;
# 注:因为使用了"--skip-grant-tables"启动mysqld服务,故不能使用"alter user"语句
mysql> alter user root@'localhost' identified by '123456';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
6、修改my.cnf配置文件以关闭免密登录
[mysqld]
# 注释或删除"--skip-grant-tables"选项
# skip-grant-tables=true
7、重启mysqld
$ systemctl restart mysqld
本文介绍了一种通过使用--skip-grant-tables参数来启动MySQL服务的方法,实现免密登录并更新root用户的密码。该方法包括停止服务、修改配置文件、更新密码等步骤。
401

被折叠的 条评论
为什么被折叠?



