Introduction MySQL 8.0 changed the default authentication plugin from `mysql_native_password` to `caching_sha2_password`. Older client drivers, connection libraries, and tools that do not support this plugin fail to connect with `Authentication plugin 'caching_sha2_password' cannot be loaded` errors.
Symptoms - `Authentication plugin 'caching_sha2_password' cannot be loaded` - `ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: cannot open shared object file` - PHP mysqli or PDO connections fail with authentication errors - Python mysqlclient or older PyMySQL versions cannot connect - Docker containers with older MySQL client images fail to connect to MySQL 8.0+
Common Causes - MySQL 8.0+ default authentication is `caching_sha2_password` - Client driver version does not support the new plugin - `caching_sha2_password.so` plugin file missing from the server - User created with `caching_sha2_password` but client only supports `mysql_native_password` - Mixed environment with old and new MySQL client libraries
Step-by-Step Fix 1. **Check the user's current authentication plugin": ```sql SELECT user, host, plugin, authentication_string FROM mysql.user WHERE user = 'app_user'; ```
- 1.**Change the user to use mysql_native_password":
- 2.```sql
- 3.ALTER USER 'app_user'@'%' IDENTIFIED WITH mysql_native_password BY 'MyS3cur3P@ss!';
- 4.FLUSH PRIVILEGES;
- 5.
` - 6.**Or create a new user with the compatible plugin":
- 7.```sql
- 8.CREATE USER 'app_user'@'%' IDENTIFIED WITH mysql_native_password BY 'MyS3cur3P@ss!';
- 9.GRANT SELECT, INSERT, UPDATE, DELETE ON mydb.* TO 'app_user'@'%';
- 10.FLUSH PRIVILEGES;
- 11.
` - 12.**Change the server default authentication plugin":
- 13.```ini
- 14.# /etc/mysql/my.cnf
- 15.[mysqld]
- 16.default_authentication_plugin = mysql_native_password
- 17.
` - 18.**For clients that support it, upgrade the driver":
- 19.```bash
- 20.# Python - upgrade to PyMySQL 0.9+ or mysqlclient 1.4+
- 21.pip install --upgrade pymysql
# PHP - ensure mysqlnd is installed sudo apt install php-mysqlnd
# Node.js - mysql2 supports caching_sha2_password npm install mysql2 ```
- 1.**Verify the plugin is loaded on the server":
- 2.```sql
- 3.SELECT PLUGIN_NAME, PLUGIN_STATUS
- 4.FROM information_schema.PLUGINS
- 5.WHERE PLUGIN_NAME = 'caching_sha2_password';
- 6.
`