即使在Linux终端中通过安全模式设置了密码,也无法访问MySql根用户 [英] Unable to access MySql root user, even after setting the password through safemode in linux terminal

查看:180
本文介绍了即使在Linux终端中通过安全模式设置了密码,也无法访问MySql根用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)服务已停止

sudo /etc/init.d/mysqld stop

2)以安全模式启动

sudo mysqld_safe --skip-grant-tables &

3)用户创建

mysql -u root

4)设置密码

UPDATE user SET Password=PASSWORD('my_password') where USER='root';

从mysql控制台退出, 并重新启动服务,并尝试使用

exit from the mysql console, and restart the service and trying to access mysql console with

mysql -u root -p my_password     

[vikram@VoltyLinux ~]$ mysql -u root -p
Enter password: *******

错误1045(28000):对用户'root'@'localhost'的访问被拒绝(使用 密码:是)

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

推荐答案

像在第2步中一样进行操作,即以安全模式重启mysql守护程序.

Go in as before in Step 2, that is, restart mysql daemon in safe-mode.

发出命令

select user,host,password from mysql.user where user='root';

将输出剪切并粘贴到文本编辑器中,以便在进行以下操作之前和之后进行比较(比较散列的密码列值).

cut and paste output into a text editor for comparison (of the hashed password column values) before and after the following.

对于每一行,请注意host列.在下面的示例中,我假设我有两行.一行以%作为主机,下一行具有localhost

For each row notice the host column. In the following example I am assuming I have two rows. One row has % as host, the next has localhost

对于具有host变体的每一行,您将发出一个命令.因此,在上面的示例中,我总共将发出2条命令,例如:

For each row that had a host variation, you will issue one command. So in my example above, I would be issuing 2 commands in total, such as:

SET PASSWORD FOR 'root'@'%' = PASSWORD('MyNewPassword');
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPassword');

运行

select user,host,password from mysql.user where user='root';

将其剪切并粘贴到文本编辑器中.请注意密码哈希的更改.

cut and paste that into text editor. Notice the change to the password hashes.

从安全模式关闭守护程序,然后正常重启.

Shutdown the daemon from safe mode, and restart normally.

尝试使用MyNewPassword以root用户身份登录

Try to login as root with MyNewPassword

以下是一些链接. 设置密码语法的一个,通常是下一个 GRANT语法的步骤.

Here are a few links. The one for SET PASSWORD Syntax, and an often next step for GRANT Syntax.

对于此问题的狭窄范围(即登录),不需要授予.但是,如果没有对数据库的适当授权,除了select now();

For the narrow scope of this question, that is to login, the grants would not be necessary. But without proper grants to databases, one would be sandboxed, not able to do much, other than simple commands like select now();

我不建议您更改密码后,您的root用户没有特权.对于普通用户而言,必须授予Google Grants.

I am not suggesting that your root user does not have privileges once the password is changed. The Grants are necessary for normal users to be sure.

这篇关于即使在Linux终端中通过安全模式设置了密码,也无法访问MySql根用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆