Python基礎之Mysql

來源:互聯網
上載者:User

標籤:nec   log   for   obj   license   bsp   info   div   odi   

1.MySQLdb 是用於Python連結Mysql資料庫的介面,它實現了 Python 資料庫 API 規範 V2.0,基於 MySQL C API 上建立的。

2.Python下MySQLdb安裝。

  (1)先下載MySQLdb安裝包,解壓。

  (2)cmd以管理員身份運行,進行MySQLdb目錄,將MySQLdb安裝至Python下:python setup.py install

 He.py代碼:

#coding=utf-8import pymysqlconn=pymysql.connect(host="127.0.0.1",port=3306,user="root",passwd="root",db="dgcms",charset="utf8")cur=conn.cursor()sql="select * from blog"cur.execute(sql)rows = cur.fetchall()for dr in rows:    print(dr)

調用代碼:

Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32Type "copyright", "credits" or "license()" for more information.>>> from jinjiemysql import *(7, ‘VB.NET‘, ‘VB.NET‘)(3, ‘go go‘, ‘er3r53r5‘)(4, ‘  C#‘, ‘RWRRWWW‘)(6, ‘object c‘, ‘object c‘)(5, ‘python‘, ‘haaaa‘)>>> 

 

Python基礎之Mysql

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.