Mac python3鏈接mysql

Mac python3鏈接mysql

安裝方法1:python

1.pip3 install --upgrade pip //升級pip版本mysql

2.sudo python3 /Library/Frameworks/Python.framework/Versions/3.xx/bin/pip3 install pymysql//安裝pymsqlgit

安裝方法2:github

git clone https://github.com/PyMySQL/PyMySQL sql

$ cd PyMySQL/ curl

$ python3 setup.py installfetch

安裝方法3:url

$ # X.X 爲 PyMySQL 的版本號 spa

$ curl -L https://github.com/PyMySQL/PyMySQL/tarball/pymysql-X.X | tar xz regexp

$ cd PyMySQL*

$ python3 setup.py install

$ # 如今你能夠刪除 PyMySQL* 目錄

安裝方法3:

import pymysqltry:    conn = pymysql.connect(host='56f34b014db78crd.sh.cdb.myqcloud.com', user='root', passwd='JinxQ007008', db='base', port=5492, charset='utf8')    cur = conn.cursor()    cur.execute('SELECT  * FROM HOME_USER')    data = cur.fetchall()    for d in data:        print("id: "+str(d[0])+' 密碼:'+d[2])    cur.close()    conn.close()except Exception:    print('查詢失敗')
相關文章
相關標籤/搜索