python import mysql code example

Example 1: how to connect to mysql database in python

import mysql.connector

cnx = mysql.connector.connect(user='scott', password='password',
                              host='127.0.0.1',
                              database='employees')
cnx.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)

Example 3: Import mysql'

LOAD DATA INFILE "name.csv" INTO TABLE "TableName"
FIELDS TERMINATED BY "sign"
LINES TERMINATED BY "sign"
IGNORE 1 LINES
(columns);