23 lines
513 B
Python
23 lines
513 B
Python
import mysql.connector
|
|
|
|
try:
|
|
# Connect to MySQL server
|
|
conn = mysql.connector.connect(
|
|
host='127.0.0.1',
|
|
user='root',
|
|
password='123456',
|
|
port=3306
|
|
)
|
|
|
|
cursor = conn.cursor()
|
|
|
|
# Create database
|
|
cursor.execute("CREATE DATABASE IF NOT EXISTS qiandao CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci")
|
|
|
|
print("Database 'qiandao' created successfully!")
|
|
|
|
cursor.close()
|
|
conn.close()
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}") |