Connect to the database in python

Create a folder and go inside of the folder

mkdir python_database
cd python_database

Installation

pip install mysql-connector-python

Now Create file db.py

## Connecting to the database

import mysql.connector as mysql

db = mysql.connect(
    host="localhost",
    user="root",
    passwd="[email protected]"
)

print(db) 
Leave a Comment