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)05/31 Report--
This article mainly shows you "pycharm2017 how to achieve the connection between python3.6 and mysql", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "pycharm2017 how to achieve the connection between python3.6 and mysql" this article.
The details are as follows
Unlike other IDE, pycharm does not need to download additional mydqldb packages, etc., pymysql can be installed automatically in pycharm, and the function is the same as the downloaded mydqldb.
First, install pymysql that comes with pycharm
1. First, open the settings settings- > protect- > protect Interpreter- > double-click pip-- on the right side of pycharm > enter pymysql-- > in the search box > then select the version and click install package, and then prompt successful later.
Second, the code part
Import pymysql # establish database connection conn=pymysql.Connect (host='localhost', port=3306, user='root', passwd=' database password', db='bigsdut', charset='utf8') # get cursor cursor=conn.cursor () # print (conn) # print (cursor) # 1, query # sql= "INSERT INTO login (user_name) from the database Pass_word) "sql=" SELECT * FROM login "# cursor execute sql statement cursor.execute (sql) # number of print (cursor.rowcount) # print execution results print (cursor.rowcount) # traversal results using fetch method there are a total of three data # rs=cursor.fetchone () # put the first result in rs # re=cursor.fetchmany (3) # put multiple results in re () # put all results in rr # where the results are processed For row in rr: print ("ID is: =% s" The name is:% s, and the password is: =% s "% row) # print (re) # output two pieces of data Because the fetch () method is based on the last fetch () method # 2 insert data sql_insert= "INSERT INTO login (user_name,pass_word) values ('ZTE', '123')" # execution statement cursor.execute (sql_insert) # transaction commit Otherwise, the database will not be updated conn.commit () print (cursor.rowcount) # modify the contents in the database sql_update= "UPDATE login SET user_name='hhh' WHERE id=3" cursor.execute (sql_update) conn.commit () # delete the contents in the database and use the try catch statement for transaction rollback try: sql_delete= "DELETE FROM login WHERE id=6" cursor.execute (sql_delete) conn.commit () except Exception as e: print (e) # transaction rollback That is, after an error occurs, it will not continue to execute, but will return to the state that the program has not been executed. The original execution does not count conn.rollback () # database connection and cursor closure conn.close () cursor.close () above is all the contents of this article "how pycharm2017 implements the connection between python3.6 and mysql". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.