MYSQL Access denied for user 'root'@'localhost'

后端 未结 3 1684
我寻月下人不归
我寻月下人不归 2020-12-11 15:49

I did the following steps to use MySQL in Ubuntu:

sudo aptitude install php5-mysql mysql-server
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables          


        
相关标签:
3条回答
  • 2020-12-11 16:08

    System like Ubuntu prefers to use auth_socket plugin for root account by default. It will try to authenticate by comparing your username in DB and process which makes mysql request; it is described in here

    The socket plugin checks whether the socket user name (the operating system user name) matches the MySQL user name specified by the client program to the server, and permits the connection only if the names match.

    Instead you may want to back with the mysql_native_password, which will require user/password to authenticate.

    About the method to achieve that, I recommend you checking this out instead.

    0 讨论(0)
  • 2020-12-11 16:11

    If you get an error message like this:

    Warning: mysql_connect(): Access denied for user: ....
    

    then the problem is that your application can not access the database. This can have several causes:

    First of all, make sure the database settings in your db-config.php (connection file for your application) are correct, specifically the name and password of your MySQL user, the name of your database, and the name of your MySQL server.

    If you're running your own server, you may need to give your MySQL user proper permissions. Log in to MySQL as the MySQL root user and issue these commands:

    GRANT ALL PRIVILEGES ON database_name TO user@host IDENTIFIED BY 'password';
    FLUSH PRIVILEGES;
    
    0 讨论(0)
  • 2020-12-11 16:16

    It was absolutely correct what you did, but I guess it's not working for one small reason.

    You should use identified by password when you are going to grant privileges like this:

    mysql> GRANT ALL PRIVILEGES ONE `*`.`*` TO 'root'@'localhost' IDENTIFIED BY PASSWORD
    '*A4B6157319038724E3560894F7F932C8886EBFCF' WITH GRANT OPTION;
    
    0 讨论(0)
提交回复
热议问题