-
Notifications
You must be signed in to change notification settings - Fork 0
/
table1.py
35 lines (30 loc) · 1.26 KB
/
table1.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
import pymysql
# Function to connect to MySQL and create the database and table
def setup_database():
connection = pymysql.connect(
host='192.168.27.185', # Replace with your MySQL server IP
user='saideep', # Replace with your MySQL username
password='Lenskart@123#', # Replace with your MySQL password
port=3306 # Default MySQL port
)
try:
with connection.cursor() as cursor:
# Create database if it does not exist
cursor.execute("CREATE DATABASE IF NOT EXISTS shuttle_state")
# Switch to the new database
cursor.execute("USE shuttle_state")
# Create table if it does not exist
cursor.execute("""
CREATE TABLE IF NOT EXISTS server_logs (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
ip VARCHAR(15) NOT NULL,
state ENUM('up', 'down') NOT NULL,
last_checked TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)
""")
connection.commit()
finally:
connection.close()
# Execute the function to set up the database and table
setup_database()