Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Steps for python3 version to operate mysql

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following is about the python3 version of the steps to operate mysql, the secret of the text is close to the topic related. So, no gossip, let's go straight to the following, I believe that after reading the python3 version of the steps to operate mysql this article will certainly benefit you.

1. Connect mysql:import pymysql

Conn=pymysql.connect ("localhost", "root", "password", "database name") # Open database connection)

Cursor=db.cursor () # use the cursor () method to create a cursor object cursor)

2. Query data

Conn.query () conn.commit () conn.close () conn=pymysql.connect (=, =) cur=conn.cursor () cur.execute () r cur: (, (cur.rownumber)) (+ (r []) + (r []) cur.close () conn.close () 3, insert data import pymysql#, open database connection db = pymysql.connect ("localhost", "testuser", "test123") "TESTDB") # use the cursor () method to get the operation cursor cursor = db.cursor () # SQL insert statement sql = "" INSERT INTO EMPLOYEE (FIRST_NAME, LAST_NAME, AGE, SEX, INCOME) VALUES ('Mac',' Mohan', 20,'M' 2000) "" try: # execute sql statement cursor.execute (sql) # submit to the database to execute db.commit () except: # roll back db.rollback () # close database connection db.close () 4, create data table import pymysql# Open database connection db = pymysql.connect ("localhost", "testuser", "test123" "TESTDB") # create a cursor object using the cursor () method cursorcursor = db.cursor () # execute SQL using the execute () method Delete cursor.execute ("DROP TABLE IF EXISTS EMPLOYEE") # create table sql = "" CREATE TABLE EMPLOYEE (FIRST_NAME CHAR (20) NOT NULL, LAST_NAME CHAR (20), AGE INT, SEX CHAR (1), INCOME FLOAT) "" cursor.execute (sql) # close database connection db.close () if the table exists

Is there anything you don't understand about the steps of operating mysql in the above python3 version? Or if you want to know more about it, you can continue to follow our industry information section.

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report