2017년 4월 18일 화요일

MySQL Python Connect Driver

-. MySQL Python Connect Driver Db Connect

#!env python3

import mysql.connector
from mysql.connector import errorcode

config = {
   'user': 'dbmgr',
   'password': 'audtlr2',
   'host': 'localhost',
   'database': 'spp',
   'raise_on_warnings': True,
   'use_pure': True,
}

try:
  cnx = mysql.connector.connect(**config)

except mysql.connector.Error as err:
  if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
    print("Something is wrong with your user name or password")
  elif err.errno == errorcode.ER_BAD_DB_ERROR:
    print("Database dose not exists")
  else:
   print(err)

else:
  cnx.close()

댓글 없음:

댓글 쓰기