-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrial2.py
More file actions
29 lines (24 loc) · 740 Bytes
/
trial2.py
File metadata and controls
29 lines (24 loc) · 740 Bytes
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
import mysql.connector
import mysql
try:
connection = (mysql.connector.connect
(
host='localhost',
user='enos',
password='2025@Redmond',
database='trial_1'
)
)
if connection.is_connected():
print("Successfully connected to MySQL database.")
# You can now create a cursor and execute SQL queries
cursor = connection.cursor()
cursor.execute("SELECT * FROM trial_1")
results = cursor.fetchall()
print(results)
except mysql.connector.Error as err:
print(f"Error connecting to MySQL: {err}")
finally:
if 'connection' in locals() and connection.is_connected():
connection.close()
print("MySQL connection closed.")