MySQLdb操作

# 查询数据库
import MySQLdb

conn = MySQLdb.connect(
	host='localhost',
	user='root',
	passwd='root',
	db='test',
	charset='utf8'
)
c = conn.cursor()
c.execute("select * from student")
rows = c.fetchall()
for item in rows:
	print(item)

# 数据库插入
import MySQLdb

conn = MySQLdb.connect(
	host='localhost',
	user='root',
	passwd='root',
	db='test',
	charset='utf8'
)
c = conn.cursor()
c.execute("insert into student (sid,sname,sage,ssex) values('09','汪晓康','19920812','男')")
conn.commit()
rows = c.fetchall()
for item in rows:
	print(item)
上一篇:Navicat for mysql命令行操作及常用语句


下一篇:Linux下MySQL主从复制(GTID)+读写分离(ProxySQL)-实施笔记