pymysql操作数据库
连接方法:
import pymysql
1、
1 def db_connect(): 2 return pymysql.connect('127.0.0.1', 'yang', '123456', 'dbtest', port=3306, charset='utf8') 3 4 db = db_connect()
2、
1 connection = pymysql.connect( 2 host='127.0.0.1', 3 port=3306, 4 user='root', 5 password='zhyea.com', 6 db='employees', 7 charset='utf8mb4', 8 cursorclass=pymysql.cursors.DictCursor)
3、
config = { 'host':'127.0.0.1', 'port':3306, 'user':'root', 'password':'zhyea.com', 'db':'employees', 'charset':'utf8mb4', 'cursorclass':pymysql.cursors.DictCursor, } # Connect to the database connection = pymysql.connect(**config)