mysql connectivity with python code example
Example 1: connect python to mysql
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword",
port = 8888,
database='whatever db you want'
)
print(mydb)
Example 2: python and mysql connectivity
import pymysql
db = pymysql.connect("database_host","username","password","database_name")
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print ("Database version : {0}".format(data))
db.close()