Cannot log in with created user in mysql

前端 未结 12 1409
小蘑菇
小蘑菇 2020-12-07 15:31

Using this command

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

I try to login with:

 mysql -         


        
相关标签:
12条回答
  • 2020-12-07 15:53

    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.

    0 讨论(0)
  • 2020-12-07 15:53

    You forgot the quotes around brian in your grant statement. Try it like this:

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

    0 讨论(0)
  • 2020-12-07 15:54

    You probably have this perpetual MySQL problem where one of the default users in the user table is '' @ localhost, which winds up denying all localhost users later in the table. What I would do is mysqldump the mysql database and look for this entry in the User table; if found, delete it and flush privileges.

    For more details see https://dev.mysql.com/doc/refman/5.5/en/connection-access.html.

    It is a common misconception to think that, for a given user name, all rows that explicitly name that user are used first when the server attempts to find a match for the connection. This is not true. The preceding example illustrates this, where a connection from h1.example.net by jeffrey is first matched not by the row containing 'jeffrey' as the User column value, but by the row with no user name. As a result, jeffrey is authenticated as an anonymous user, even though he specified a user name when connecting.

    0 讨论(0)
  • 2020-12-07 16:05

    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
    0 讨论(0)
  • 2020-12-07 16:10

    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

    0 讨论(0)
  • 2020-12-07 16:10

    Change to native password using this command:

    ALTER USER 'username'@'hostname' IDENTIFIED WITH mysql_native_password BY 'password';
    
    0 讨论(0)
提交回复
热议问题