0

I am trying to connect python to mysql by this code-- (I am using the mysql.connect library)

import mysql.connector

cnx = mysql.connector.connect(user='root', 
                          password='password',
                          host='127.0.0.1',
                          database='db')
print(cnx)
cnx.close()

But it continues to throw the error--

Traceback (most recent call last):
File "D:/ted/main.py", line 5, in <module>
database='db')
File "C:\Program Files (x86)\Python36-32\lib\mysql\connector\__init__.py", 
line 179, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Program Files (x86)\Python36-32\lib\mysql\connector\connection.py", 
line 94, in __init__
self.connect(**kwargs)
File "C:\Program Files (x86)\Python36-32\lib\mysql\connector\abstracts.py", 
line 722, in connect
self._open_connection()
File "C:\Program Files (x86)\Python36-32\lib\mysql\connector\connection.py", 
line 211, in _open_connection
self._ssl)
File "C:\Program Files (x86)\Python36-32\lib\mysql\connector\connection.py", 
 line 141, in _do_auth
auth_plugin=self._auth_plugin)
File "C:\Program Files (x86)\Python36-32\lib\mysql\connector\protocol.py", 
line 102, in make_auth
auth_data, ssl_enabled)
File "C:\Program Files (x86)\Python36-32\lib\mysql\connector\protocol.py", 
line 58, in _auth_response
auth = get_auth_plugin(auth_plugin)(
 File "C:\Program Files (x86)\Python36- 
32\lib\mysql\connector\authentication.py", line 191, in get_auth_plugin
"Authentication plugin '{0}' is not supported".format(plugin_name))
mysql.connector.errors.NotSupportedError: Authentication plugin 
'caching_sha2_password' is not supported

Process finished with exit code 1

I have started the mysql sever in workbench and the also checked the status. Also database named "db" is also there Also checked if the host is proper. -->Removed ssl also.

1 Answers1

1

It seems that your MySQL Server version is 8.x and in that case the default MySQL connector is caching_sha2_password. In the other hand your error is maybe because your python client connector does not support this Authentication Plugin and you should explicitly change the Authentication Plugin to the old one (mysql_native_password).

cnx = mysql.connector.connect(user='root', password='password',
                          host='127.0.0.1', database='db',
                          auth_plugin='mysql_native_password')
Reza Behzadpour
  • 638
  • 5
  • 16