Install PyMySql template
pip install pymysql
Configure MySQL connection parameters
pymysql.Connect()
host , Post, user, passwd, db, charset
Get cursor() object
cursor()
Execute MySql statement
cursor ().execute()
cursor().commit()
Specific code:
# - coding: utf-8 --
import pymysql
def load_all_from_mysql():
connect = pymysql.Connect(
host = 'localhost',
port = 3306,
user = 'root',
password = '******< span style="color: #800000;">',
db = 'Database name',
charset = 'utf8'
)
cursor = connect.cursor()
sql = "SELECT * from table name"
cursor.execute(sql)
# print(cursor.fetchall())
for row in cursor.fetchall():
print(row)
load_all_from_mysql()
# - coding: utf-8 --
import pymysql
def load_all_from_mysql():
connect = pymysql.Connect(
host = 'localhost',
port = 3306,
user = 'root',
password = '******< span style="color: #800000;">',
db = 'Database name',
charset = 'utf8'
)
cursor = connect.cursor()
sql = "SELECT * from table name"
cursor.execute(sql)
# print(cursor.fetchall())
for row in cursor.fetchall():
print(row)
load_all_from_mysql()