conn = pymysql.connect(host="127.0.0.1",#默认是本机 port=3306, #默认3306 user="root",#必填 password='密码',#必填 db="库名")#必填 #如果没有库会报pymysql.err.internalerror: (1049, "unknown database '库名'") 所有我们编辑可以这样 try: conn = pymysql.connect(host="127.0.0.1",#默认是本机 port=3306, #默认3306 user="root",#必填 password='16745',#必填 db="asds",)#必填 except pymysql.err.internalerror: print('没有库')
cursor = conn.cursor(pymysql.cursors.dictcursor) #自定义游标类型为字典 cursor = conn.cursor()#默认是元祖
普通提交
count = cursor.execute('show tables') #返回值为受到影响的数据条数
防注入提交
table_name = input('table name :') count = cursor.execute('select table %s',(name,))
默认显示之前那一次显示的内容,只显示查看相关语法的内容,为返回值 cursor.fetchall() #查看全部 cursor.fetchone() #查看当前游标位置的一个值 cursor.fetchmay(n) #查看当前游标位置的n值
相对位置
cursor.scroll(1, "relative")
cursor.scroll() #默认是相对位置
绝对位置
cursor.scroll(0, "absolute")
如对本文有疑问, 点击进行留言回复!!
在Ubuntu/Linux环境下使用MySQL开放/修改3306端口和开放访问权限
ORM框架Peewee(高级连接)peewee连接池、主从、重连、ssh连接
记一次Mysql主从复制延迟,Waiting for dependent transaction to commit
网友评论