Reputation: 415
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?
Upvotes: 0
Views: 66
Reputation: 2534
You should give proper keyword including database
mysql.connector.connect(user='user', password='password',
host='127.0.0.1',
database='db_name')
Upvotes: 1