Skip to content

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:

  1. MySQL 8.0 deprecated and disabled the plugin by default
  2. MySQL 9.0 completely removed the plugin from distributions
  3. macOS Homebrew installations default to recent MySQL versions
  4. Applications using legacy authentication methods fail to connect

The safest solution is installing MySQL 8.4, the last version supporting native authentication:

bash
# 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:

bash
mysql --version
# Should show: mysql  Ver ... for macos... (Homebrew mysql@8.4)

::warning After downgrading, restart your database server:

bash
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:

  1. Edit your MySQL configuration file:
bash
nano /opt/homebrew/etc/my.cnf
  1. Add this configuration under [mysqld]:
ini
[mysqld]
mysql_native_password=ON
  1. Save changes and restart MySQL:
bash
brew services restart mysql@8.4
  1. Verify plugin status in MySQL console:
sql
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

sql
SELECT user, host, plugin FROM mysql.user;

+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| your_db_user     | %         | mysql_native_password |
+------------------+-----------+-----------------------+

B. Update User Authentication Plugin

sql
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:

  1. Install PyMySQL:
bash
pip install pymysql
  1. Update your connection method:
python
# Before using MySQLdb:
import pymysql
pymysql.install_as_MySQLdb()  # Drop-in replacement

# SQLAlchemy connection string format:
'mysql+pymysql://user:password@localhost/dbname'

Final Recommendations

  1. New projects: Use caching_sha2_password for enhanced security
  2. Legacy applications: Downgrade to MySQL 8.4 for compatibility
  3. Cross-platform projects: Use PyMySQL connector for consistent behavior
  4. 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.