用的是 Python 3.6.0
windows 用户
windows 用户可以直接在 pycharm 中的preference 中安装符合当前版本的 mysql-connector-python 和 mysqlclient 包
image.pngmac 用户
方法1
mac 用户可以在 /Users/XXX/Downloads/pycharmqt/mysql 里面先安装一个mysql-connector-python-2.1.5-macos10.12 (资源请去官网搜索;同事找我来拿)
brew install mysql
export PATH=$PATH:/usr/local/mysql/bin
pip3 install mysqlclient
方法2
同 windows 用户
详情请参见:
http://stackoverflow.com/questions/25459386/mac-os-x-environmenterror-mysql-config-not-found
测试代码
import MySQLdb
db = MySQLdb.connect(host="192.168.1.251",user="root",passwd="root", db="LangLibUser")
c = db.cursor()
c.execute("SELECT Id from SNS_UserBaseInfo limit 1")
print(c.fetchone())
测试成功结果如下:
/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/bin/python3.6
/Users/liuyuewei/Downloads/PyCharm/test0206/test.py
('O10171638’,)
Process finished with exit code 0
网友评论