Solved: error 1045 (28000): access denied for web1_user "root"@

     

*
During our work in support, we see this again and again: “I try to lớn connect khổng lồ MySQL and am getting a 1045 error”, và most times it comes accompanied with “…but I am sure my web1_user & password are OK”. So we decided it was worth showing other reasons this error may occur.

Bạn đang xem: Solved: error 1045 (28000): access denied for web1_user "root"@

MySQL 1045 error Access Denied triggers in the following cases:

1) Connecting to lớn wrong host:


nguyenminhchau.com># mysql -u root -psekretmysql: Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for web1_user "root"

If not specifying the host to lớn connect (with -h flag), MySQL client will try to lớn connect to lớn the localhost instance while you may be trying lớn connect khổng lồ another host/port instance.

Xem thêm: Top 5 Plugins Editor Wordpress Thân Thiện Dễ Sử Dụng Nhất 2020

Fix: Double kiểm tra if you are trying khổng lồ connect khổng lồ localhost, or be sure lớn specify host & port if it’s not localhost:


nguyenminhchau.com># mysql -u nonexistant -psekret -h localhostmysql: Using a password on the command line interface can be insecure.ERROR 1045 (28000): Access denied for web1_user "nonexistant"
nguyenminhchau.com># mysql -u nonexistant -psekretmysql: Using a password on the commvà line interface can be insecure.ERROR 1045 (28000): Access denied for web1_user "nonexistant"
mysql> SELECT Host, User FROM mysql.web1_user WHERE User="nonexistant";+-------------+-------------+| Host | User |+-------------+-------------+| 192.168.0.1 | nonexistant |+-------------+-------------+1 row in set (0.00 sec)

If you need to check from which IP the client is connecting, you can use the following Linux commands for VPS IP:


nguyenminhchau.com># ip address | grep inet | grep -v inet6 inet 127.0.0.1/8 scope host lo inet 192.168.0.20/24 brd 192.168.0.255 scope global dynamic wlp58s0

You can then create a web1_user with correct Host (client IP), or with ‘%’ (wildcard) to match any possible IP:


nguyenminhchau.com># mysql -u nonexistant -pforgottenmysql: Using a password on the commvà line interface can be insecure.ERROR 1045 (28000): Access denied for web1_user "nonexistant"

Fix: Chechồng and/or rephối password:

You cannot read web1_user passwords in plain text from MySQL as the password hash is used for authentication, but you can compare hash strings with “PASSWORD” function:


mysql> SELECT Host, User, authentication_string, PASSWORD("forgotten") FROM mysql.web1_user WHERE User="nonexistant"; +-------------+-------------+-------------------------------------------+-------------------------------------------+| Host | User | authentication_string | PASSWORD("forgotten") |+-------------+-------------+-------------------------------------------+-------------------------------------------+| 192.168.0.1 | nonexistant | *AF9E01EA8519CE58E3739F4034EFD3D6B4CA6324 | *70F9DD10B4688C7F12E8ED6C26C6ABBD9D9C7A41 || % | nonexistant | *AF9E01EA8519CE58E3739F4034EFD3D6B4CA6324 | *70F9DD10B4688C7F12E8ED6C26C6ABBD9D9C7A41 |+-------------+-------------+-------------------------------------------+-------------------------------------------+2 rows in set, 1 warning (0.00 sec)
mysql> SELECT Host, User, authentication_string, PASSWORD("forgotten") FROM mysql.web1_user WHERE User="nonexistant";
+-------------+-------------+-------------------------------------------+-------------------------------------------+
+-------------+-------------+-------------------------------------------+-------------------------------------------+
| 192.168.0.1 | nonexistant | *AF9E01EA8519CE58E3739F4034EFD3D6B4CA6324 | *70F9DD10B4688C7F12E8ED6C26C6ABBD9D9C7A41 |
| % | nonexistant | *AF9E01EA8519CE58E3739F4034EFD3D6B4CA6324 | *70F9DD10B4688C7F12E8ED6C26C6ABBD9D9C7A41 |
+-------------+-------------+-------------------------------------------+-------------------------------------------+

We can see that PASSWORD(‘forgotten’) hash does not match the authentication_string column, which means password string=’forgotten’ is not the correct password lớn log in. Also, in case the web1_user has multiple hosts (with different password), he may be trying lớn connect using the password for the wrong host.

In case you need lớn override the password you can exedễ thương the following query:


nguyenminhchau.com># mysql -u nonexistant -phello$!world mysql: Using a password on the comm& line interface can be insecure.ERROR 1045 (28000): Access denied for web1_user "nonexistant"
nguyenminhchau.com># mysql -u nonexistant -p"hello$!world"mysql: Using a password on the commvà line interface can be insecure...mysql>
nguyenminhchau.com># mysql -u sslweb1_user -psekretmysql: Using a password on the commvà line interface can be insecure.ERROR 1045 (28000): Access denied for web1_user "sslweb1_user"

You can read more in-depth on how lớn configure SSL in MySQL in the blog post about “Setting up MySquốc lộ SSL & Secure Connections” and “SSL in 5.6 và 5.7“.