how to connect python to mysql
snippet in sql

how to connect python to mysql

user7130


import mysql.connector

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

  
print(mydb) 

connect python to mysql

user1821

import mysql.connector
mydb = mysql.connector.connect(
  host="localhost",
  user="yourusername",
  password="yourpassword",
  port = 8888, #for Mamp users
  database='whatever db you want'
)
print(mydb)