Cannot log in with created user in mysql

2019-01-16 10:02发布

Using this command

GRANT ALL PRIVILEGES ON *.* to 'brian'@'%' identified by 'password';

I try to login with:

 mysql -u brian -ppassword

The error is:

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

I am doing this as root and I did try to flush privileges.

I tried this with countless users but it does not seem to work. I can create a user with no password and login works. Command line and from phpmyadmin

Also check to see if the user was in mysql.user which it is.

Show grants for brian shows:

| GRANT ALL PRIVILEGES ON *.* TO 'brian'@'%' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' |

12条回答
干净又极端
2楼-- · 2019-01-16 10:23

The mysql docs have this to say: (from http://dev.mysql.com/doc/refman/5.1/en/adding-users.html):

Two of the accounts have a user name of monty and a password of some_pass. Both accounts are superuser accounts with full privileges to do anything. The 'monty'@'localhost' account can be used only when connecting from the local host. The 'monty'@'%' account uses the '%' wildcard for the host part, so it can be used to connect from any host.

It is necessary to have both accounts for monty to be able to connect from anywhere as monty. Without the localhost account, the anonymous-user account for localhost that is created by mysql_install_db would take precedence when monty connects from the local host. As a result, monty would be treated as an anonymous user. The reason for this is that the anonymous-user account has a more specific Host column value than the 'monty'@'%' account and thus comes earlier in the user table sort order.

With this in mind I would recommend you create a 'brian'@'localhost' user with the same privileges.

查看更多
戒情不戒烟
3楼-- · 2019-01-16 10:26

None of the solutions provided here worked. After loads of error and trial I realised that I had special characters in the password. Changing password without special characters solved the issue

查看更多
啃猪蹄的小仙女
4楼-- · 2019-01-16 10:27

I had a similar problem attempting to connect to a Maria DB running on Ubuntu after upgrading to 17.04.

The default was to listen only on localhost, 127.0.0.1.

To make MySQL/Maria listen on all available ports and interfaces I needed to explicitly specify bind-address=0.0.0.0. I added this line to the end of the file /etc/mysql/my.cnf, i.e.

...
[client-server]

# Import all .cnf files from configuration directory

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
bind-address=0.0.0.0

Then...

sudo /etc/init.d/mysql restart 
查看更多
▲ chillily
5楼-- · 2019-01-16 10:30

Similar problem occurred for me even after verifying i haven't entered a wrong password, i couldn't login. Below two steps solved my problem.

  1. Dropping test database
  2. Deleting anonymous user
查看更多
男人必须洒脱
6楼-- · 2019-01-16 10:31
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
查看更多
倾城 Initia
7楼-- · 2019-01-16 10:31

You can also connect from another host and then the localhost anonymous user is bypassed and you can remove it and flush privileges:

mysql -u brian -ppassword -h 'other_host_than_localhost'
查看更多
登录 后发表回答