Connect to mysql server without sudo

后端 未结 9 1170
暖寄归人
暖寄归人 2020-12-02 08:39

The command:

mysql -u root -p

gives the error:

ERROR 1698 (28000): Access denied for user \'root\'@\'localhost\'


        
相关标签:
9条回答
  • 2020-12-02 09:02

    In the comment of the question you answer you referenced, it reads

    Ok, just try to analyze all of the directories down in the path of the socket file, they need to have o+rx and the sock file too (it's not a good idea to make it modifiable by others).

    You can also try to remove mysql.sock and then restart mysqld, the file should be created by the daemon with proper privileges.

    This seemed to work for this question(the one you said you looked at) so it may work for you as well

    0 讨论(0)
  • 2020-12-02 09:06

    I have solved this problem using following commands.

    CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON * . * TO 'username'@'localhost';
    FLUSH PRIVILEGES;
    

    Here, username = any user name you like.

    and password = any password you like.

    0 讨论(0)
  • 2020-12-02 09:08

    Only the root user needs sudo requirement to login to mysql. I resolved this by creating a new user and granting access to the required databases:

    CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
    
    GRANT ALL PRIVILEGES ON database_name.* TO 'newuser'@'localhost';
    

    now newuser can login without sudo requirement:

    mysql -u newuser -p
    
    0 讨论(0)
提交回复
热议问题