forked from jmbharathram/executeoncommand
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql-program.py
More file actions
23 lines (21 loc) · 813 Bytes
/
mysql-program.py
File metadata and controls
23 lines (21 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import mysql.connector
from mysql.connector import Error
try:
connection = mysql.connector.connect(host='service ip',
database='mysql',
user='root',
password='abc')
if connection.is_connected():
db_Info = connection.get_server_info()
print("Connected to MySQL Server version ", db_Info)
cursor = connection.cursor()
cursor.execute("select database();")
record = cursor.fetchone()
print("You're connected to database: ", record)
except Error as e:
print("Error while connecting to MySQL", e)
finally:
if connection.is_connected():
cursor.close()
connection.close()
print("MySQL connection is closed")