简体   繁体   English

修改密码后无法登录MySQL

[英]Can't Login To MySQL After Changing Password

I'm trying to set a user's password but after I set it, I still can't log in as that user. 我正在尝试设置用户的密码,但是在设置密码后,我仍然无法以该用户身份登录。

$ mysql -uroot -p mydb
Enter password:

mysql> select user,host,password from mysql.user;
...
webapp | % | *.... |

mysql> show grants for webapp@'%';
GRANT USAGE ON *.* TO 'webapp'@'%' IDNETIFIED BY PASSWORD '*...'
GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON 'mydb'.* TO 'webapp'@'%'

mysql> set password for webapp@'%'=PASSWORD('mypassword');
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit

$ mysql -uwebapp -p mydb
Enter password:
ERROR 1045 (28000): Access denied for user 'webapp'@'localhost' (using password: YES)

I just set the password and it does not work, what is happening? 我只设置了密码,但它不起作用,这是怎么回事?

By the way the user's table only has one entry with the name 'webapp' and its host is '%' 顺便说一句,用户表只有一个名为“ webapp”的条目,其主机为“%”

I'm using mysql 5.1.67. 我正在使用MySQL 5.1.67。 I also tried restarting mysqld, but it still doesn't work. 我也尝试重新启动mysqld,但仍然无法正常工作。

After all the tests we've done on the comments the issue you're having is that you have skip-networking on your server which makes it not listen to TCP/IP connections at all. 在对注释进行所有测试之后,您遇到的问题是服务器上的skip-networking使其根本无法监听TCP / IP连接。

Since its not listening to the TCP/IP connections your MySQL server is using the socket to connect hence you need to have a user entry that contains localhost as the socket uses localhost . 由于它不监听TCP / IP连接,因此您的MySQL服务器正在使用套接字进行连接,因此您需要具有一个包含localhost的用户条目,因为套接字使用localhost

As you have tested, adding the localhost granted use fixed the issue and it also defines the fact that it does make a difference whether you do have or not a user with localhost for this sort of specific server configurations for example. 如您所测试的,添加被授予使用权限的localhost解决了该问题,并且还定义了这样一个事实,即您是否确实有使用localhost的用户来进行此类特定服务器配置,这确实有所不同。

In your case the command run to accomplish the localhost granted use was: 在您的情况下,运行以完成localhost授予使用的命令是:

        GRANT SELECT, 
              INSERT, 
              UPDATE, 
              DELETE, 
              EXECUTE 
           ON 'your_database_name_here'.* 
           TO 'your_username_here'@'localhost' 
IDNETIFIED BY 'your_password_here';
FLUSH PRIVILEGES;

Just as further reference: 作为进一步参考:

skip-networking : Don't listen for TCP/IP connections at all. skip-networking:根本不监听TCP / IP连接。 All interaction with mysqld must be made via Unix sockets. 与mysqld的所有交互都必须通过Unix套接字进行。 This option is highly recommended for systems where only local requests are allowed. 对于仅允许本地请求的系统,强烈建议使用此选项。 Since you need to allow remote connection this line should be removed from my.cnf or put it in comment state. 由于需要允许远程连接,因此应从my.cnf中删除此行或将其置于注释状态。

http://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_skip-networking http://dev.mysql.com/doc/refman/5.5/zh-CN/server-options.html#option_mysqld_skip-networking

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM