In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
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.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.