mysql.connector.errors.NotSupportedError: Authentication plugin 'mysql_native_password' is not supported only with pyinstaller exe

Question:

I am fighting to find a solution for my problem:
When I start my Python application in my IDE, the database connection is working fine. But when I build an exe with pyinstaller with the following command python3 -m PyInstaller .home.py and start the application and trigger the connection to the db it gives me the following error:

"mysql.connector.errors.NotSupportedError: Authentication plugin 'mysql_native_password'is not supported"

Previously I had the same error with "caching_sha2_password" instead of "mysql_native_password", then I changed the db plugin to "mysql_native_password" but it still doesn’t work in the exe.
My database is running in a Docker Container. The root user, which I use for the connection has also mysql_native_password as the authentication plugin.

enter image description here

However, somehow the connection to the db works every time when I start my application from my IDE. This problem only occurs, after I have exported my application into an exe with pyinstaller.

The connection to the db looks like this:

mysql.connector.connect(
      host="localhost",
      user="user",
      passwd="password",
      database="db_name"     
    )

And yes, I have already checked, that I only have mysql-connector-python installed.

I would be very glad if you could help me out, as this is the final step of my application to be ready for shipment.
Thank you in advance!

Asked By: Whosayin20

||

Answers:

After I could not find an answer for my problem, I just switched to Postgres and used the corresponding Python driver. Now it works!

Answered By: Whosayin20

After a lot of stress, I decided to install an older version of mysql-connector-python from this site https://downloads.mysql.com/archives/c-python/

I installed the 8.0.20 and for now, working.
test later and verify.
I had this same bug for weeks.

The only difference with you is that I didn’t use pyinstaller, but the CX_Freeze.

Answered By: GustSR

When the .exe file is created "caching_sha2_password" is not found…you have to turn debug mode on when creating the .exe file, then you will see the error message.

So the way to resolve the issue is to import "caching_sha2_password" explicitly in your python script, like so:

from mysql.connector.plugins import caching_sha2_password

Answered By: JHW