HOME/Articles/

mysql example mysqlConnect-Json (snippet)

Article Outline

Python mysql example 'mysqlConnect-Json'

Modules used in program:

  • import mysql.connector
  • import json

python mysqlConnect-Json

Python mysql example: mysqlConnect-Json

import json
import mysql.connector

class dbase:

    def connect_db():
        with open('dbdata.json') as f:
            db_data = json.load(f)
        db_connect = mysql.connector.connect(**db_data)