HOME/Articles/

mysql example dbSockMysql (snippet)

Article Outline

Python mysql example 'dbSockMysql'

Modules used in program:

  • import mysql.connector

python dbSockMysql

Python mysql example: dbSockMysql

from config import env
import mysql.connector

db_cred = {
    'host': env('DB_HOST'),
    'database': env('DB_NAME'),
    'user': env('DB_USER'),
    'password': env('DB_PSW')
}
conn = mysql.connector.connect(**db_cred)
conn.close