1, sudo apt-get install Python-setuptools
2, sudo apt-get install Libmysqld-dev
3, sudo apt-get install Libmysqlclient-dev
4, sudo apt-get install Python-dev
5, sudo easy_install Mysql-python
Under test:
In the Python interactive window, import mysqldb try, without error, it proves that the installation is good.
Prepare
Python 2.7
Connector/python 2.1.1
Installation
1, download the source package.
wget http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.1.tar.gz
2, decompression.
tar -zxvf mysql-connector-python-2.1.1.tar.gz
3, installation.
python setup.py install
Note: root privileges are required
Programming
#Coding:utf8#use Connector/python for query operations. ImportMysql.connector#Create a connectionConfig = { 'User':'Uzone', 'Password':'Uzone', 'Host':'127.0.0.1', 'Port': 19816, 'Database':'UCGC_SDK'}conn= Mysql.connector.connect (* *config)#Creating CursorsCur =conn.cursor ()#Execute Query SQLsql ="SELECT notice_id,notice_name,creator,ctime,modifier,mtime from Notice"cur.execute (SQL)#Get query ResultsResult_set =Cur.fetchall ()ifResult_set: forRowinchResult_set:Print "%d,%s,%s,%d,%s,%s"% (row[0],row[1],row[2],row[3],row[4],row[5])#Close cursors and connectionscur.close () conn.close ( )
Partial reprint: http://aofengblog.blog.163.com/blog/static/6317021201522084715866/
Python_ Basic Learning _04_mysql Library verification and installation (Mysql-python)