MySQL is a third-party module that needs to install PIP install Pymysql First,
After SQL executes, there are three data acquisition functions
Cur.fetchone () #获取第一条数据, and so on and so on, the second execution will take the first one that removes the first execution result (second result, and so on)
Cur.fetchmany (3) #获取结果中的多少条
Cur.fetchall () # Get all the results
ImportPymysql fromPymysql.cursorsImportDictcursorcoon= Pymysql.connect (host='211.149.218.16', port=3306,user='Jxz', passwd='123456', db='Jxz', charset='UTF8') #建立数据库连接cur= Coon.cursor (Dictcursor)#Create a cursor, warehouse administrator, specify a cursor type, return a dictionary, if you do not specify a return type, the default is to return a tupleSql='select * from Stu limit 2,9;'Insert_sql='INSERT INTO Stu VALUE ("Nhy");'Cur.execute (insert_sql) cur.execute (SQL)#Execute SQL statement forCinchCur#Direct loop cursors, each of which is the data for each column Print(c) Res= Cur.fetchall ()#gets the results of the SQL statement execution, all at onceCoon.commit ()#SubmitPrint(res[0][1]) cur.close () #关闭游标coon. Close () #关闭数据库连接
Python Basics-manipulating MySQL