'MySQL is not connecting through python

MySQL is not connecting and show error

I install mysql.connector package through pip

This is Code

import mysql.connector
connection = mysql.connector.connect(host = "localhost", user = "root",passwd = "268455")
print(connection)

This is Error im getting

 D:\Python>"C:/Users/Abdul Muqeet/AppData/Local/Programs/Python/Python38/python.exe" 
"d:/Python/exmaple (mySQL).py"
 Traceback (most recent call last):
 File "d:/Python/exmaple (mySQL).py", line 2, in <module>
 connection = mysql.connector.connect(host = "localhost", user = "root",passwd = "268455")
 File "C:\Users\Abdul Muqeet\AppData\Roaming\Python\Python38\site- 
packages\mysql\connector\__init__.py", line 179, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\Abdul Muqeet\AppData\Roaming\Python\Python38\site- 
packages\mysql\connector\connection.py", line 95, in __init__
self.connect(**kwargs)
File "C:\Users\Abdul Muqeet\AppData\Roaming\Python\Python38\site- 
packages\mysql\connector\abstracts.py", line 716, in connect
self._open_connection()
File "C:\Users\Abdul Muqeet\AppData\Roaming\Python\Python38\site- 
packages\mysql\connector\connection.py", line 208, in _open_connection
self._do_auth(self._user, self._password,
File "C:\Users\Abdul Muqeet\AppData\Roaming\Python\Python38\site- 
packages\mysql\connector\connection.py", line 137, in _do_auth
packet = self._protocol.make_auth(
File "C:\Users\Abdul Muqeet\AppData\Roaming\Python\Python38\site- 
packages\mysql\connector\protocol.py", line 99, in make_auth
packet += self._auth_response(client_flags, username, password,
File "C:\Users\Abdul Muqeet\AppData\Roaming\Python\Python38\site- 
packages\mysql\connector\protocol.py", line 58, in _auth_response
auth = get_auth_plugin(auth_plugin)(
File "C:\Users\Abdul Muqeet\AppData\Roaming\Python\Python38\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 search many sites,i did in same way all did but still getting error



Solution 1:[1]

Issue is solved. I install mysql-connector package while I need to install mysql-connector-python package. First uninstall mysql-connector package and then install mysql-connector-python package.

Solution 2:[2]

You have to include the database that you want to connect with it and the message can not be like you use.

A example:

def MySQLConnect(usernameStr, passwordStr, hostStr, databaseStr, conPrint = True):
    #ESTABLISH THE CONNECTION WITH THE DATABASE
    try:
        con = mysql.connector.connect(
            user = usernameStr,
            password = passwordStr,
            host = hostStr,
            database = databaseStr)

        if conPrint: print('Connection established successfully with the database')
        return con
    except Error:
        print(Error)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 asantz96