码迷,mamicode.com
首页 > 数据库 > 详细

python-pymysql

时间:2018-07-17 16:34:56      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:sele   mit   执行sql   port   sel   hal   cut   .com   连接   

1.基本用法

import pymysql
#建立连接
conn=pymysql.connect(
    host=‘localhost‘,
    port=3306,
    user=‘root‘,
    password=‘123456‘,
    db=‘mydb‘
)
#创建游标
cursor=conn.cursor()
#执行sql
effect_row=cursor.execute("select * from student")
#查询第一行
#row_1=cursor.fetchone()
#print(row_1)
#查询全部
row_all=cursor.fetchall()
print(row_all)

conn.commit()
cursor.close()
conn.close()

python-pymysql

标签:sele   mit   执行sql   port   sel   hal   cut   .com   连接   

原文地址:http://blog.51cto.com/13803166/2145793

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!