简体   繁体   中英

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 '%'

I'm using mysql 5.1.67. I also tried restarting mysqld, but it still doesn't work.

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.

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 .

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.

In your case the command run to accomplish the localhost granted use was:

        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. All interaction with mysqld must be made via Unix sockets. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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