connecting python to mysql code example
Example 1: 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()
Example 2: mysql connection python
from sqlalchemy import types, create_engine
import pymysql
try:
conn = create_engine('mysql+pymysql://user:pass@IP/database_name')
print("MySQL Connection Sucessfull!!!!!!!!!!!")
except Exception as err:
print("MySQL Connection Failed !!!!!!!!!!!")
print(err)