1import mysql.connector
2
3cnx = mysql.connector.connect(user='scott', password='password',
4 host='127.0.0.1',
5 database='employees')
6cnx.close()
1import mysql.connector
2mydb = mysql.connector.connect(
3 host="localhost",
4 user="yourusername",
5 password="yourpassword",
6 port = 8888, #for Mamp users
7 database='whatever db you want'
8)
9print(mydb)
1import pymysql
2
3############### CONFIGURE THIS ###################
4# Open database connection
5db = pymysql.connect("database_host","username","password","database_name")
6##################################################
7
8# prepare a cursor object using cursor() method
9cursor = db.cursor()
10
11# execute SQL query using execute() method.
12cursor.execute("SELECT VERSION()")
13
14# Fetch a single row using fetchone() method.
15data = cursor.fetchone()
16print ("Database version : {0}".format(data))
17
18# disconnect from server
19db.close()
1from sqlalchemy import types, create_engine
2import pymysql
3
4try:
5 conn = create_engine('mysql+pymysql://user:pass@IP/database_name')
6 print("MySQL Connection Sucessfull!!!!!!!!!!!")
7
8except Exception as err:
9
10 print("MySQL Connection Failed !!!!!!!!!!!")
11 print(err)
12