您好,登錄后才能下訂單哦!
本文主要給大家簡單講講使用pyMySQL如何成功連接MySQL數(shù)據(jù)庫,相關(guān)專業(yè)術(shù)語大家可以上網(wǎng)查查或者找一些相關(guān)書籍補充一下,這里就不涉獵了,我們就直奔主題吧,希望使用pyMySQL如何成功連接MySQL數(shù)據(jù)庫這篇文章可以給大家?guī)硪恍嶋H幫助。
下載pyMySQL模塊包
[root@kurol ~]# python36 -m pip install pyMySQL Collecting pyMySQL Downloading PyMySQL-0.7.11-py2.py3-none-any.whl (78kB) 100% |################################| 81kB 8.9kB/s Installing collected packages: pyMySQL Successfully installed pyMySQL-0.7.11
創(chuàng)建py文件
[root@kurol ~]#touch mysqltest.py [root@kurol ~]#vim mysqltest.py
#!/usr/bin/python36 # -*- coding: UTF-8 -*- # import os,sys import pymysql try: conn = pymysql.connect(host='localhost',user='root',passwd='',db='db_student') except Exception as e: print (e) sys.exit() cursor = conn.cursor() sql = "select * from stu_inf" cursor.execute(sql) data = cursor.fetchall() if data: for x in data: print (x[0],x[1],x[2],x[3],x[4],x[5]) cursor.close() conn.close()
使用pyMySQL如何成功連接MySQL數(shù)據(jù)庫就先給大家講到這里,對于其它相關(guān)問題大家想要了解的可以持續(xù)關(guān)注我們的行業(yè)資訊。我們的板塊內(nèi)容每天都會捕捉一些行業(yè)新聞及專業(yè)知識分享給大家的。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。