Python_ Basic Learning _04_mysql Library verification and installation (Mysql-python)

Source: Internet
Author: User

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)

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.