-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateDatabase.py
More file actions
24 lines (22 loc) · 833 Bytes
/
Copy pathcreateDatabase.py
File metadata and controls
24 lines (22 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pymysql.cursors
from config import dbConfig
def createDatabase(cursor):
try:
cursor.execute(
"CREATE DATABASE {} DEFAULT CHARACTER SET '{}'".format(dbConfig['db'], dbConfig['charset']))
except Exception as err:
print("Failed creating database: {}".format(err))
exit(1)
else:
print("DATABASE `{}` created".format(dbConfig['db']))
def process():
global connection, cursor
try:
connection = pymysql.connect(**dbConfig)
except Exception as err:
print("Connection error : {}".format(err))
connection = pymysql.connect(user = dbConfig['user'], host = dbConfig['host'], charset = dbConfig['charset'])
cursor = connection.cursor()
createDatabase(cursor)
else:
print("DATABASE `{}` exists".format(dbConfig['db']))