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")