Home > Mobile >  Error: 1045 (28000) when connecting to mysql with python
Error: 1045 (28000) when connecting to mysql with python

Time:04-17

def create_server_connection(host_name, user_name, user_password):
connection = None
try:
    connection = mysql.connector.connect(
        host = host_name,
        user = user_name,
        passwd = user_password
    )
    print("database connection successfully completed")
except Error as err:
    print(f"Error: '{err}'")
return connection

pw = ""
connection = create_server_connection("localhost", "root", pw)

I am setting up a connection from Jupyter Notebook to MySQL. I'm using localhost and the root user, which has no password. I got this error message below:

Error: '1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)'

Could anyone help? Thanks.

CodePudding user response:

Exactly, you are probably using the wrong variable which in your own case is specified passwd instead of password BUT in the event you still have an error even after this you can also refer to this post from Jetbrains Blog. https://blog.jetbrains.com/datalore/2022/02/14/how-to-run-sql-from-jupyter-notebook-two-easy-ways/

CodePudding user response:

I think you just have the incorrect keyword name for password. It should be

connection = mysql.connector.connect(
    host = host_name,
    user = user_name,
    password = user_password
)

Here is the documentation for a simple connection from the MySQL website. https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html

  • Related