Get the App
SLTechnology News&Howtos  ›  Database  › 

A brief Analysis of the methods of operating pymysql Database

Shulou Source: shulou.com Published: 2022-06-01 20:14:42 10月05日 Update

This article mainly gives you a brief analysis of the methods of operating the pymysql database, and you can check the relevant professional terms on the Internet or find some related books to supplement them, so we will not dabble here, go straight to the topic, and hope to bring you some practical help.

Import pymysql# acquires a database connection. Note that if it is of type UTF-8, you need to develop a database db= pymysql.connect (host= "127.0.0.1", user= "root", passwd= "123456", db= "mysql", charset='utf8') # create a cursor object using the cursor () method cursorcursor = db.cursor () # execute the SQL query cursor.execute ("SELECT user,host") using the execute () method Password from user ") # use the fetchall () method to get all rows. Data = cursor.fetchall () print (data) cursor.close () # close cursor db.close () # close database connection

Examples of adding, deleting and modifying operations:

Import pymysqldb = pymysql.connect (host='10.3.1.174',user='root',password='123456',db='test') cursor = db.cursor () # SQL insert data sql = "INSERT INTO employee (first_name, last_name, age, sex, income)"\ "VALUES ('wow,' Eason', '29th,' M' '8000') "# SQL update data # sql =" UPDATE employee first_name = Wang WHERE first_name = w "# SQL delete data # sql =" DELETE FROM employee WHERE age > 20 "try: cursor.execute (sql) db.commit () except: db.rollback () db.close ()

A brief analysis of the methods of operating the pymysql database will first tell you here, for other related issues you want to know can continue to pay attention to our industry information. Our section will capture some industry news and professional knowledge to share with you every day.

Tags: Data databases methods specialties cursors industries expertise topics books content actual objects news terminology plates knowledge examples types information questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS OPPO Reno Huawei Redmi Linux