If you recently upgraded to MySQL 8.4 and encountered a connection error related to mysql_native_password
, you’re not alone. MySQL 8.4 has deprecated and disabled the mysql_native_password
plugin by default, causing issues in apps or frameworks still relying on it for authentication.
In this guide, you’ll learn why this is happening and how to resolve it using supported methods — or temporarily re-enable the plugin for backward compatibility.
🚫 The Error
When connecting your PHP app to a MySQL 8.4 database, you might see an error like:
Authentication plugin 'mysql_native_password' cannot be loaded: plugin not enabled
This happens because MySQL 8.4 no longer enables mysql_native_password
by default. It’s part of a broader move toward better security with the caching_sha2_password
plugin.
✅ Recommended Fix: Switch to caching_sha2_password
PHP has supported caching_sha2_password
since PHP 7.4+, so updating your user accounts to use this plugin is the most future-proof fix.
Step 1: Identify Affected Users
Run this query in your MySQL CLI:
SELECT user, host, plugin FROM mysql.user WHERE plugin='mysql_native_password';
Step 2: Alter Users
For each affected user, run:
ALTER USER 'your_user'@'your_host' IDENTIFIED WITH caching_sha2_password BY 'your_password';
Replace 'your_user'
, 'your_host'
, and 'your_password'
with actual values.
🩹 Temporary Workaround: Re-Enable the Plugin
If you’re stuck on an older PHP version (pre-7.4) or can’t update your application just yet, you can re-enable mysql_native_password
for now.
⚠️ Warning: This is not future-proof. MySQL 9.0 will remove the plugin entirely.
Step 1: Edit MySQL Configuration
Open your my.cnf
or my.ini
file and add:
[mysqld]
mysql_native_password=ON
Step 2: Restart MySQL
Restart the MySQL service:
sudo service mysql restart
🧠 Final Thoughts
The best long-term solution is to adopt the caching_sha2_password
plugin and keep your PHP stack updated. The temporary workaround should only be used while preparing your app for migration.
Leave a Reply