Linux密码正确也进不去mysql,即使在Linux终端中通过安全模式设置了密码,也无法访问MySql根用户...

1) service stoped

sudo /etc/init.d/mysqld stop

2) started in safe mode

sudo mysqld_safe --skip-grant-tables &

3) user created

mysql -u root

4) setting passwd

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

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: *******

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

password: YES)

解决方案

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

Issue the command

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.

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

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');

run

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.

Try to login as root with MyNewPassword

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

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();

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值