1, install plug-in online many not long-winded.
2. Create a table after connecting to the database
Mysqldbconn = MySQLdb.connect (=, =, =, =, =,) cur = conn.cursor () Cur.execute ()
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/76/51/wKioL1ZO-0HjHFVZAAAaKB1VhV8560.png "title=" execution result " Width= "height=" border= "0" hspace= "0" vspace= "0" style= "width:132px;height:100px;" alt= " Wkiol1zo-0hjhfvzaaaakb1vhv8560.png "/>
3. Add a piece of data
Mysqldbconn = mysqldb.connect ( =, =, =, =, =, ) Cur = conn.cursor () Cur.execute () #增cur. Close () #关闭游标conn. Commit () #提交数据 (do not submit statements that cannot be insert cannot appear) Conn.close () #关闭连接
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/76/51/wKioL1ZO_nOASXr8AAAhZ7CugMM247.png "title=" The result of the execution. png "width=" height= "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:132px;height:100px; "alt=" Wkiol1zo_ Noasxr8aaahz7cugmm247.png "/>
4. Delete a piece of data
Mysqldbconn = MySQLdb.connect (=, =, =, =, =,) cur = conn.cursor () Cur.execute () Cur.close () Conn.commit () Conn.close ()
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/76/52/wKiom1ZPAWTzAed6AAAZsvlngOU103.png "title=" delete. png "Width=" height= "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:132px;height:100px; "alt=" Wkiom1zpawtzaed6aaazsvlngou103.png "/>
5. Modify a piece of data
Mysqldbconn = MySQLdb.connect (=, =, =, =, =,) cur = conn.cursor () Cur.execute () Cur.close () Conn.commit () Conn.close ()
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/76/52/wKiom1ZPAtzy1pgwAABMB5Ktcm4814.png "title=" Change the result. png "width=" height= "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:132px;height:100px "alt=" Wkiom1zpatzy1pgwaabmb5ktcm4814.png "/>
6. Query data
conn =. Connect (=, =, =, =, =,) cur = conn.cursor () Ll=cur.execute () ll
So we can only find out a few data, can't find the complete data
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/76/52/wKiom1ZPBUjQ_g4dAAAUlpBZaXo365.png "title=" the number of bars. png "alt=" Wkiom1zpbujq_g4daaaulpbzaxo365.png "/>
After calling the Fetchmang () function, you can use the For loop to query the data
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/76/51/wKioL1ZPB02zk6u4AAB2lbT6ebI935.png "title=" Querying the database. png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:200px;height:200px "alt=" Wkiol1zpb02zk6u4aab2lbt6ebi935.png "/>
Python operations Database (MySQL)