How to fix WordPress database connection for MySQL 82018-10-27 | 13 comments
Very recently I have been upgrading software on my servers to latest one and took the risk of upgrading MySQL to latest 8.0.x version. You can read here how to upgrade WordPress to MySQL 8. In this article I will show how to fix WordPress database connection for MySQL 8.
As many recently have experienced this resulted in my WordPress sites showing this error message:
Error establishing a database connection.
The cause of that is very simple though. MySQL 8 have changed from using native encryption for passwords to a more standardized approaches. As a matter of fact, this change happened even earlier, in release 5.7. However, in MySQL 8 the team changed default value of
default_authentication_plugin configuration variable from previous
What this means is that when a client connects to MySQL without specifying which password encryption method it uses MySQL assumes it to be using
caching_sha2_password. But most of clients currently in use are assuming to use
Here is how you can fix this issue:
Firstly you need make sure you have a backup of any files you will be changing. In this guide we will be changing MySQL configuration file, so let’s back it up first. I always recommend using current date and backup sequence number in backup names to easier identify them and being able to keep multiple backups from before:
$ sudo cp /etc/my.cnf /etc/my.cnf.backup.20181027.001
Now let’s go and edit MySQL configuration file:
$ sudo nano /etc/my.cnf
In this file locate
[mysqld] section there and add the configuration lines as follows:
There may be other configuration lines between those, but there should be no other section header between them.
After this you need to restart MySQL server process:
$ sudo systemctl restart mysqld
All done. Now your WordPress should be able to connect to MySQL 8 without any problems. In the future when the community will update
mysqlnd client library to use new encryption methods this may be no longer needed, but as of now it still is.
Please let me know in the comments if this solution helped you to fix wordpress database connection for MySQL 8!