-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_conn.py
18 lines (17 loc) · 841 Bytes
/
db_conn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import mysql.connector
def db_connect(host,user, psswd,):
try:
connection = mysql.connector.connect(host = host, user = user, psswd = psswd)
if connection.is_connected():
print("Your are now connected to MySql server")
cursor = connection.cursor()
database_name = input("Enter the database name: ")
create_db_query = f"CREATE DATABASE {database_name}"
cursor.execute(create_db_query)
print(f"Database '{database_name}' created sucessfully")
cursor.close()
connection.close()
print("MySql server conncetion is close")
except mysql.connector.Error as error:
print('Error', error)
db_connect(host=input("Enter the host name: "), user=input("Enter the user name: "), psswd=input("Enter the password: "))