0

I've been trying to connect Python and MySql but I keep getting errors. This is my code:

import mysql.connector
mydb = mysql.connector.connect( 
    host="localhost", 
    user="kdvis", 
    password="root")
    
print (mydb)

And this is the error I'm getting:

Traceback (most recent call last):
    File "C:\Users\kdvis\Desktop\flies\11\python\connection1.py", line 9, in <module>
    mydb = mysql.connector.connect(
    
    AttributeError: module 'mysql' has no attribute 'connector'

I've reconfigured MySql, gotten a caching_sha2_password error, a sha256 password requires SSL error, an access denied for user@localhost error, tried to change my root password using alter keyword on MySql, and read almost every solution but none worked.
Help would be appreciated very much.

Shadow
  • 33,525
  • 10
  • 51
  • 64
Kaveri V
  • 1
  • 1
  • Try to update it first: 'python -m pip install mysql-connector-python --upgrade' and do you have python 2 or 3? Because I tried it with Python 3 and it works. – Nexarius Apr 08 '21 at 12:27
  • @Nexarius It says that the requirement is already satisfied. (Python 3.8, I mentioned it in the heading) – Kaveri V Apr 08 '21 at 12:30
  • Does this answer your question? [AttributeError: module 'mysql' has no attribute 'connector'](https://stackoverflow.com/questions/46503776/attributeerror-module-mysql-has-no-attribute-connector) – sahasrara62 Apr 08 '21 at 12:34
  • @sahasrara62 thanks, but no I've visited the page 3 times – Kaveri V Apr 08 '21 at 12:39

1 Answers1

0

Have you installed mysql as from pip. If from other source remove it and install it from pip using coomand.

pip install mysql