python_基礎學習_04_mysql庫驗證與安裝(mysql-python)

來源:互聯網
上載者: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

 

測試下:

在python互動式視窗,import MySQLdb 試試,不報錯的話,就證明安裝好了。

 

預備

Python 2.7
Connector/Python 2.1.1

安裝

1、下載源碼包。

wget http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.1.tar.gz

2、解壓縮。

tar -zxvf mysql-connector-python-2.1.1.tar.gz

3、安裝。

python setup.py install

註:需要root許可權

編程
#coding:utf8# 使用 Connector/Python 進行查詢操作。import mysql.connector# 建立串連config = {          ‘user‘:‘uzone‘,           ‘password‘:‘uzone‘,           ‘host‘:‘127.0.0.1‘,           ‘port‘:19816,            ‘database‘:‘ucgc_sdk‘}conn = mysql.connector.connect(**config)# 建立遊標cur = conn.cursor()# 執行查詢SQLsql = "SELECT notice_id,notice_name,creator,ctime,modifier,mtime FROM notice"cur.execute(sql)# 擷取查詢結果result_set = cur.fetchall()if result_set:    for row in result_set:        print "%d, %s, %s, %d, %s, %s" % (row[0],row[1],row[2],row[3],row[4],row[5])# 關閉遊標和串連        cur.close()conn.close()

部分轉載:http://aofengblog.blog.163.com/blog/static/6317021201522084715866/

 

python_基礎學習_04_mysql庫驗證與安裝(mysql-python)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.