Python Basics-manipulating MySQL

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.