mysql_native_password Authentication Plugin Missing on macOS
Problem Statement
When working with MySQL on macOS systems, you may encounter this error after upgrading MySQL or switching development environments:
MySQLdb.OperationalError: (2059, "Authentication plugin 'mysql_native_password' cannot be loaded:
dlopen(.../mysql_native_password.so) no such file")
Key characteristics of this issue:
- Works on Windows/Linux but fails on macOS (especially Apple Silicon)
- Occurs when connecting from Python applications (Flask/Django/etc.)
- Affects MySQL installations via Homebrew after upgrading to MySQL 9.0+
- Database access works with other tools but fails with application connections
- Common with XAMPP installations using mysql_native_password authentication
The core issue stems from MySQL 9.x removing support for the legacy mysql_native_password
plugin while your application configuration still relies on it.
Why This Happens
Recent MySQL versions dropped the mysql_native_password
plugin for security reasons:
- MySQL 8.0 deprecated and disabled the plugin by default
- MySQL 9.0 completely removed the plugin from distributions
- macOS Homebrew installations default to recent MySQL versions
- Applications using legacy authentication methods fail to connect
Solution 1: Downgrade MySQL to Compatible Version (Recommended)
The safest solution is installing MySQL 8.4, the last version supporting native authentication:
# Uninstall existing MySQL version
brew uninstall mysql
# Install MySQL 8.4
brew install mysql@8.4
# Link the installation
brew link --force mysql@8.4
# Add to shell path
echo 'export PATH="/opt/homebrew/opt/mysql@8.4/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Verify installation:
mysql --version
# Should show: mysql Ver ... for macos... (Homebrew mysql@8.4)
::warning After downgrading, restart your database server:
brew services restart mysql@8.4
::
Solution 2: Enable Native Password in MySQL Configuration (For MySQL 8.x)
If you must keep MySQL 8.x, manually enable the native plugin:
- Edit your MySQL configuration file:
nano /opt/homebrew/etc/my.cnf
- Add this configuration under
[mysqld]
:
[mysqld]
mysql_native_password=ON
- Save changes and restart MySQL:
brew services restart mysql@8.4
- Verify plugin status in MySQL console:
SHOW PLUGINS;
# Verify 'mysql_native_password' is ACTIVE
::tip MySQL 8.x users: After enabling native authentication in my.cnf
, restarting the server may be required for changes to take effect. ::
Solution 3: Upgrade Authentication Method (Secure Alternative)
Migrate to the modern caching_sha2_password
plugin:
A. Check Current Authentication Method
SELECT user, host, plugin FROM mysql.user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| your_db_user | % | mysql_native_password |
+------------------+-----------+-----------------------+
B. Update User Authentication Plugin
ALTER USER 'your_user'@'host'
IDENTIFIED WITH caching_sha2_password
BY 'your_secure_password';
FLUSH PRIVILEGES;
Additional Solution: Python Driver Workaround
Bypass native authentication by switching to pure-Python connectors:
- Install PyMySQL:
pip install pymysql
- Update your connection method:
# Before using MySQLdb:
import pymysql
pymysql.install_as_MySQLdb() # Drop-in replacement
# SQLAlchemy connection string format:
'mysql+pymysql://user:password@localhost/dbname'
Final Recommendations
- New projects: Use
caching_sha2_password
for enhanced security - Legacy applications: Downgrade to MySQL 8.4 for compatibility
- Cross-platform projects: Use PyMySQL connector for consistent behavior
- Security-critical systems: Always prefer SHA-2 authentication methods
For MySQL servers pre-8.x where ALTER USER
fails, upgrade to newer MySQL version or modify users through temporary skip-grant-tables
mode.