I’m working on a blog project using Python and Flask, and I’m using the MySQL database from XAMPP for user registration. The project worked perfectly on my Windows machine, but after switching to macOS, I’ve been encountering various issues with the registration process. I’ve managed to resolve most of the issues, but I’m still struggling with one particular error. I’ve been working on this for a week now and could use some help.
Error Details:
MySQLdb.OperationalError: (2059, “Authentication plugin ‘mysql_native_password’ cannot be loaded: dlopen(/opt/homebrew/Cellar/mysql/9.0.1/lib/plugin/mysql_native_password.so, 0x0002): tried: ‘/opt/homebrew/Cellar/mysql/9.0.1/lib/plugin/mysql_native_password.so’ (no such file), ‘/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/mysql/9.0.1/lib/plugin/mysql_native_password.so’ (no such file), ‘/opt/homebrew/Cellar/mysql/9.0.1/lib/plugin/mysql_native_password.so’ (no such file)”)
enter image description here
Context:
• The application is running on macOS using XAMPP.
• The database is configured correctly, and I can connect to it using other tools.
• I’ve tried various solutions like asking chatgpt or searching on google
Has anyone encountered this issue or have any suggestions on how to resolve it?
Thanks in advance for your help!
2
You need to install [email protected] or [email protected] on MacOS. Because native authentication plugin was removed from mysql 9.0
Run the command line below to uninstall [email protected]
brew uninstall mysql
Run the command lines below to install [email protected]
brew install [email protected]
ln -s /opt/homebrew/opt/[email protected] /opt/homebrew/opt/mysql
- If you need to have mysql first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/mysql/bin:$PATH"' >> ~/.zshrc
7
Downgrading to an insecure solution is not a good idea. There are good reasons for the old authentication hashing algorithm to be abandoned as can be found here.
A better solution is to upgrade the hashing algorithm to a more secure one. If setting up a database this should happen automatically. If upgrading from an earlier version there is a nice write-up here that explains how to temporarily disable authentication to allow manual upgrades of the password hashing algorithm.
Reproduction of the steps in the link:
-
Disable the Grant Tables:
Edit the MySQL configuration file, typically located at
/etc/my.cnf
.Add the following line under the [mysqld] section to disable the grant tables:
[mysqld] skip-grant-tables
-
Restart MySQL
-
Connect to MySQL as the root user:
mysql -u root
-
Refresh the privileges:
FLUSH PRIVILEGES;
-
Check for users using the mysql_native_password plugin:
SELECT User, Host, plugin FROM mysql.user WHERE plugin = 'mysql_native_password';
-
Update the user(s) to use the
caching_sha2_password
plugin, e.g.:ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'new_password';
-
Re-enable Grant Tables:
After updating, remove or comment out the skip-grant-tables line from the MySQL configuration file.
-
Restart MySQL to apply the changes
1
Mysql’s native authentication plugin was removed from mysql 9.0. You need to change the authentication plugin used for the users to one of the supported ones or downgrade mysql from the experimental 9.0 to a production 8.4 or 8.0 version.
9
Adding a solution specific to my situation. Installed MySQL by way of MAMP (cause it’s ‘easy’). Needed workbench specifically for the ERD generation. Workbench couldn’t connect to local mysql installed by mamp; other clients could connect.
MySQL installed by MAMP creates a root user using mysql_native_password plugin which is not supported anymore in MySQL 8.4.
Followed instructions here to change PWD storage for that same root user to sha2 cache:
https://php.watch/articles/fix-php-mysql-84-mysql_native_password-not-loaded
Relevant commands are:
-
Check that it is in fact native password problem:
SELECT user, host, plugin from mysql.user WHERE plugin=’mysql_native_password’;
-
Change the user(s) to remove the need for native password plugin:
ALTER USER ‘USERNAME’@’HOST’ IDENTIFIED WITH caching_sha2_password BY ‘NEW_PASSWORD’;
MySQL includes mysql_native_password plugin which implements Native Pluggable Authentication
This plugin is deprecated since v8.0 and it’s disabled by default in [email protected] but removed as of [email protected]
To fix this issue:
-
Install [email protected]
brew install [email protected]
-
Start the server
brew services start [email protected]
-
Enable
mysql_native_password
in the configuration file
In my case config path is : /opt/homebrew/etc/my.cnf
sudo nano /opt/homebrew/etc/my.cnf
Your final file configuration should look like this:
# Default Homebrew MySQL server config
[mysqld]
mysql_native_password=ON # Add this line <----
# Only allow connections from localhost
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1