In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1, add a table using Python
# Import the module used to operate the database
Import pymysql
# establishing a connection database object
Conn=pymysql.connect (host='127.2.2.2',user='root',passwd='123456',db='records')
# create a cursor
Cur=conn.cursor ()
# execute the sql statement with the method in the cursor
Cur.execute ("create table people (name char (20), height int (3), weight int (3)")
# close the cursor after the statement is executed
Cur.close ()
# close the connection to the database
Conn.close ()
The above code can be viewed in the database after execution, and a table of people has been created.
2, insert a piece of data in the table.
# execute the sql statement with the method in the cursor
Cur.execute ("insert into people values ('tom',110,34)")
# submit the insert operation you just did to make it effective
Conn.commit ()
3. Modify a piece of data in the table to change height to 177,
# execute the sql statement with the method in the cursor
Cur.execute ("update people set height=177 where name='tom'")
# submit the insert operation you just did to make it effective
Conn.commit ()
4, query the data in the table
# execute the sql statement with the method in the cursor
Cur.execute ("select * from people")
The # fetchall method can capture the result of the statement executed by select above.
Print (cur.fetchall ())
5. Delete the data in the table
# execute the sql statement with the method in the cursor
Cur.execute ("delete from people where name='tom'")
# submit the insert operation you just did to make it effective
Conn.commit ()
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.