-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_db.py
40 lines (32 loc) · 1.07 KB
/
create_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import discord
from discord.ext import commands
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
import mysql.connector
from mysql.connector import Error
import pandas as pd
from secret.config import get_sql_root_pw, get_api_token, get_service_key_path
pw = get_sql_root_pw()
def create_db_connection(host_name, user_name, user_password):
connection = None
try:
connection = mysql.connector.connect(
host=host_name,
user=user_name,
passwd=user_password,
)
print("MySQL Database connection successful")
except Error as err:
print(f"Error: '{err}'")
return connection
connection = create_db_connection("localhost", "root", pw)
def create_database(connection, query):
cursor = connection.cursor()
try:
cursor.execute(query)
print("Database created successfully")
except Error as err:
print(f"Error: '{err}'")
create_database_query = "CREATE DATABASE QuickQuestions"
create_database(connection, create_database_query)