pythondockerauthenticationpyinstallermysql-connector-python

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


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!


Solution

  • 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