Database version retrieving using Python

#username of MySQL: root
#Password: root
#Hostname: localhost
# Database Name in MySQL: test

import mysql.connector
x = mysql.connector.connect(user='root', password='root',host='localhost',database='test')
# prepare a cursor object using cursor() method
cursor = x.cursor()
# execute SQL query using execute() method.
cursor.execute("SELECT VERSION()")
# Fetch a single row using fetchone() method.
data = cursor.fetchone()
print ("Database version : %s " % data)
# disconnect from server
x.close()

1 comment:

samala swathi said...

Thank you so much for sharing with us. Appreciate them.Python Online Training Hyderabad