skip to Main Content

I’m trying to establish a connection to MySQL server from IDLE and I can’t figure out why I’m getting an error.

>>> dbconfig = {'host': '127.0.0.1',
        'user': 'vsearch',
        'password': 'vsearchpasswd',
        'database': 'vsearchlogDB'}
>>> import mysql.connector
>>> conn = mysql.connector.connect(**dbconfig)
Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    conn = mysql.connector.connect(**dbconfig)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/__init__.py", line 179, in connect
    return MySQLConnection(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/connection.py", line 95, in __init__
    self.connect(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/abstracts.py", line 719, in connect
    self._open_connection()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/connection.py", line 208, in _open_connection
    self._do_auth(self._user, self._password,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/connection.py", line 137, in _do_auth
    packet = self._protocol.make_auth(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/protocol.py", line 99, in make_auth
    packet += self._auth_response(client_flags, username, password,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/protocol.py", line 58, in _auth_response
    auth = get_auth_plugin(auth_plugin)(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/authentication.py", line 190, in get_auth_plugin
    raise errors.NotSupportedError(
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported

I’ve tried these suggestions I found on stackoverflow :

  • shutting down mysql.server, installing mysql-connector-python and restarting mysql.server
  • passing an auth_plugin argument to the connect() method (as seen below)
auth_plugin='mysql_native_password'
  • made sure MySQL in listening to port 3306 (answer below)
localhost:mysql (LISTEN)

Versions:

  • mysql Ver 8.0.32 for macos12.6 on x86_64 (Homebrew)
  • Python 3.9.1
  • MacOS 12

2

Answers


  1. Chosen as BEST ANSWER

    Managed to fix issue by uninstalling MySQL connector and reinstalling it. Had issues with permissions so make sure you have permissions to read and write in connector directories.

    This tutorial might help if your trying to connect to MySQL with MySQL-connector-python : https://pynative.com/python-mysql-database-connection/


  2. MySQL 8 introduces a new default authentication plugin called caching_sha2_password. The error is likely because your clients/connectors do not (yet) support the caching_sha2_password plugin.

    To resolve this issue, you may consider using mysql_native_password as the default authentication for MySQL 8.0 server.

    Add the following entry in the MySQL configuration file:

    1. [mysqld]
    2. default-authentication-plugin=mysql_native_password
      Restart the MySQL server to load the change.

    Then, you might need to recreate your database user to use this authentication plugin.
    First, drop the user:

    1DROP USER [email protected];

    Then create it again with the mysql_native_password plugin:

    1CREATE USER ‘vsearch’@’127.0.0.1’ IDENTIFIED WITH mysql_native_password BY ‘vsearchpasswd’;

    Assign the proper privileges for database vsearchlogDB:
    1GRANT ALL PRIVILEGES ON vsearchlogDB.* to ‘vsearch’@’127.0.0.1’;

    Re-run your application and you should be good.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search