0

I am simply following this example https://www.w3schools.com/python/python_mysql_create_db.asp

using this code

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="yourusername",
  passwd="yourpassword"
)

I leave localhost unchanged, but set the user/pass to be my personal user/password I use to log into the computer. I am getting

mysql.connector.errors.DatabaseError: 2003 (HY000): Can't connect to MySQL server on 'localhost' (61)

but am surprised to find no clear explanation as to why online. It seems like such a simple line of code... I don't know what I'm doing wrong. What am I doing wrong?

1 Answer 1

1

You should give proper keyword including database

mysql.connector.connect(user='user', password='password',
                              host='127.0.0.1',
                              database='db_name')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.