亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何連接Python中的MySQL數據庫?

如何連接Python中的MySQL數據庫?

桃花長相依 2019-06-04 17:09:39
如何連接Python中的MySQL數據庫?如何使用python程序連接到MySQL數據庫?
查看完整描述

3 回答

?
交互式愛情

TA貢獻1712條經驗 獲得超3個贊

以下是一種方法,使用MySQLdb,它只支持Python 2:

#!/usr/bin/pythonimport MySQLdb# Connectdb = MySQLdb.connect(host="localhost",
                     user="appuser",
                     passwd="",
                     db="onco")cursor = db.cursor()# Execute SQL select statementcursor.execute
                     ("SELECT * FROM location")# Commit your changes if writing# In this case, we are only reading data# db.commit()
                     # Get the number of rows in the resultsetnumrows = cursor.rowcount# Get and display one row at a 
                     timefor x in range(0, numrows):
    row = cursor.fetchone()
    print row[0], "-->", row[1]# Close the connectiondb.close()

參考文獻


查看完整回答
反對 回復 2019-06-04
  • 3 回答
  • 0 關注
  • 651 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號