Python connection MySQL

Source: Internet
Author: User

ImportPymysqlImportRandomconn= Pymysql.connect (host ='127.0.0.1', user ='Lick', passwd='123456', db='pythontest') #建立连接Print(conn) forIinchRange (1,10000): IDM= Random.randint (1000,10000) name="Test"+str (IDM) cur=conn.cursor () #建立游标, a cursor is the basic execution SQL statement Cur.execute ("Show Tables") #执行sql语句 SQL="INSERT into TB01 values (%d, '%s ');"%(idm,name) cur.execute (SQL) Cur.execute ("SELECT * from Tb01") Conn.commit () #提交sql语句到databaseret=Cur.fetchall () #获取语句执行的信息Print(ret) forXinchret:Print(x) cur.close () conn.close ()

Python connection MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.