Python interacts with MySQL, the official website is supported by Connertor, and Connector/python now supports up to python3.4:
http://dev.mysql.com/downloads/connector/python/
However, 3.5 can be connected using open source Pymysql:
Https://github.com/PyMySQL/PyMySQL
Simple use of Sample:
MySQL Database preparation:
Use Testcreate table testtbl (tId int not null, Tname nvarchar (a) NOT null)
Python adds data to MySQL:
Import pymysqladdquery = "inset into TTT (tid,tname) VALUES (1, ' Test A ');" conn = pymysql.connect (host= ' localhost ', user= ' lybing ', password= ' lybing ', db= ' test ', port=3306, charset= ' UTF8 ') with Conn.cursor () as Cursor:affect = Curor.execute (addquery) conn.commit () #很重要, do not forget Conn.close ()
Other operations on their own good experiment, simple to give the focus:
Cur.fetchone () Print U ' checks only one record ' Cur.fetchmany (2) Print U ' multiple data: ' Cur.fetchall () print U ' all data: ' For data in Result:print DATAC Onn.commit () Cur.close () Conn.close ()
This article is from the "lybing" blog, make sure to keep this source http://lybing.blog.51cto.com/3286625/1812782
python3.5 interacting with MySQL