2016-10-02 106 views
0

安装mysql时,我没有在root密码字段中输入任何内容,但是当我运行mysql -u root时,我仍然得到了Access denied for user 'root'@'localhost'无法将root密码设置为空

我以安全模式启动mysql,没有授权表,sudo mysql_safe --skip-grant-tables &,然后跳入mysql -u root没有问题。

然后我做了use mysql; update user set authentication_string=null where user='root';和我:

Query OK, 0 rows affected (0.00 sec) 
Rows matched: 1 Changed: 0 Warnings: 0 

任何人有原因的密码没有更新任何见解?

回答

0

我不得不把插件设置为mysql_native_password,所以密码重置部分看起来是这样的:

update user set authentication_string=password(''), plugin='mysql_native_password' where user='root'; FLUSH PRIVILEGES; 
0

你忘

FLUSH PRIVILEGES; 

步步它会是这样

停止MySQL服务器。

sudo /etc/init.d/mysql stop 

启动mysqld配置。

sudo mysqld --skip-grant-tables & 

以root用户身份登录MySQL。

mysql -u root mysql 

用您的新密码替换YOURNEWPASSWORD!

UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit; 
+0

看看输出的最后几行。最后一行应该说'行匹配:1改变:1警告:0'。 'FLUSH PRIVILEGES;'这里什么都不做,因为没有任何变化。而且,在MySQL 5.7中'password'字段已被'authentication_string'替换。 –

+0

是的,你是对的,我没有看到“0行受影响”。选择用户表并查看表中存在的根用户 –