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--
Mysql database module for advanced functions of Python
Install python mysql components
# yum-y install MySQL-python.x86_64
The following is illustrated by an example:
> import MySQLdb
> conn = MySQLdb.connect (user='root',passwd='2wdc%RDX',host='localhost') # Connect to the database (connection to the server)
> cur = conn.cursor () # create a cursor (saved through an object (cur)
> conn.select_db ('redmine') # Select the database to be added, deleted and modified
> cur.execute ("insert into userinfo (name,age,gender) value ('loyu',20,'m')") # execute (sql statement) sends sql statements
> sqli = "insert insto userinfo (name,age,gender) value (% sdepartment% s)" # leave the value to be passed later by using the object method
>
> sqlim = "insert insto userinfo (name,age,gender) values (% SCHI% SJO% s)" # create multiple
> cur.executemany (sqlim, [('axiomagen5 records`), (' baggage page3 recordingdf'), ('cedarmine3df')]) # executemany passes multiple values by using lists
> cur.execute ("select * from users")
4L
> cur.fetchone () # print a piece of data (with pointer) each time a query is executed
> > cur.fetchone ()
>
> cur.fetchmany (4) # fetchmany prints 4 table data in a table by list
> cur.fetchmany (cur.execute ("select * from users")) # fetchmany prints all the data in the table as a list
> cur.close () # close the cursor
> conn.close () # close the connection
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.