Permission error when trying to access database [closed]

6

  

Error: SQLSTATE [28000] [1045] Access denied for user 'root' @ 'localhost'   (using password: YES)

    
asked by anonymous 06.02.2014 / 21:19

4 answers

4

I have already faced this error. Is root configured to use a password? You can test this hypothesis by typing this:

mysql -h localhost -u root

Note: does not have the option -p to give the password

    
06.02.2014 / 21:37
5

This error occurs because of the host. It may be the host that he listens to or permission.

Try changing localhost to 127.0.0.1

If it does not resolve, give root permission to localhost

Enter the mysql console by opening a terminal and run

mysql -h localhost -u root

If you have a password, do so

mysql -h localhost -u root -p

When you enter execute the following command

GRANT ALL PRIVILEGES ON *.* TO root@'localhost'

The part after @ is the host that makes the connection, so you should give permission to all the hosts that should make the connection. on the host you can specify a domain or even use the '%' wildcard to allow access to any host. Be careful not to leave access to any host on production servers as this is a very large security failure.

If it does not resolve, make sure the password is correct.

    
06.02.2014 / 23:17
3

This problem suggests that you are probably accessing MySQL without specifying the user and giving a password to a non-root user. When changing the server, for some reason the default user has become root, so the password must be wrong.

If this is indeed the case, I recommend that you always explicitly connect to the database using a username and password instead of assuming the default connection.

    
06.02.2014 / 23:03
2

This error happened because the password that was specified in the script, where the connection is made to the database, was different from the root password of my machine. Silly mistake for lack of attention but that is of experience to help the brothers.

    
07.02.2014 / 05:50