Mac python3连接mysql
安装方法1:
1.pip3 install --upgrade pip //升级pip版本
2.sudo python3 /Library/Frameworks/Python.framework/Versions/3.xx/bin/pip3 install pymysql//安装pymsql
安装方法2:
git clone https://github.com/PyMySQL/PyMySQL
$ cd PyMySQL/
$ python3 setup.py install
安装方法3:
$ # X.X 为 PyMySQL 的版本号
$ curl -L https://github.com/PyMySQL/PyMySQL/tarball/pymysql-X.X | tar xz
$ cd PyMySQL*
$ python3 setup.py install
$ # 现在你可以删除 PyMySQL* 目录
安装方法3:
import pymysql
try:
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('查询失败')