简体   繁体   中英

Cannot connect to database server, access denied to user root@%

I'm receiving this error when trying to open my database connection: "Cannot connect to database server your connection failed for user root@% to database [mydatabase] Please:

  1. check mysql is running on localhost
  2. check mysql is reachable on 3306
  3. check root has rights to connect to localhost
  4. Make sure youre both providing a password if needed"

I'm working on Mysql workbench on a windows 10 machine. I think my root privileges have been dropped (not sure how) so any advice on that also would be fab... thanks:)

Can you provide additional info on your setup, incl. versions of MySQL server and the client applications? You mention you can still connect, if so, what command do you use, can you query all from table mysql.user and post? Also, query the table mysql.user for plugin info , because in fresh versions of MySQL server 8.0 and up according to MySQL Documentation ( 6.4.1.2 Caching SHA-2 Pluggable Authentication ) the server by default uses new authentication method via authentication plugin caching_sha2_password . In this case the password is encrypted either by the virtue of secure connection or with RSA public_key. Then the encrypted password gets decrypted on the server by the private RSA key. For example, connections from older clients or connectors within applications might fail due to incompatibility. If you use compatible clients and authentication plugin caching_sha2_password , the connection between client and server may fail due to:

  1. Incorrect password.
  2. No secure (SSL) connection established.
  3. No public RSA key presented by the client.

In case 3, quoting the docs:

Client users can obtain the RSA public key two ways:

The database administrator can provide a copy of the public key file.

A client user who can connect to the server some other way can use a SHOW STATUS LIKE 'Caching_sha2_password_rsa_public_key' statement and save the returned key value in a file.

If you can connect to the database with any client, obtain the public key and use it to configure another client. Alternatively, the public key for RSA connection can be obtained from the server data directory. On Windows 10 it is usually C:\ProgramData\MySQL\MySQL Server 8.0\Data

example server data directory location on a windows 10 default installation

So, if the user has caching_sha2_password set and you have the public RSA key for the MySQL server you can use it to establish connection. If the user has mysql_native_password the cause be different.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM