-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMySQLServer.py
31 lines (26 loc) · 1001 Bytes
/
MySQLServer.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
import mysql.connector
from mysql.connector import Error
def create_database():
try:
# Connect to the MySQL server (update with your MySQL username and password)
connection = mysql.connector.connect(
host="localhost",
user="your_username",
password="your_password"
)
if connection.is_connected():
# Create a cursor object
cursor = connection.cursor()
# Create database if it doesn't exist
cursor.execute("CREATE DATABASE IF NOT EXISTS alx_book_store")
print("Database 'alx_book_store' created successfully!")
except mysql.connector.Error as e:
print(f"Error: {e}")
finally:
# Close the cursor and connection
if connection.is_connected():
cursor.close()
connection.close()
print("MySQL connection is closed")
# Run the function to create the database
create_database()