用Python连接MySQL(版本5.7)数据库时需要用到MySQL模块,但是Python并没有自带MySQL模块,需要自行安装,也就是MySQL for Python(MySQL-python)python3 将其模块改名为MySQLClient。
在终端输入:(默认你已经安装了MySQL、pip)
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile
重新打开一个终端:
pip install MySQL-python
如果遇到:error:command'cc' failed with exit status 1这个问题,就用下面这个命令:
xcode-select --install
等待几分钟安装成功后,再输入:
pip install MySQL-python
终端输入:
python
>>>import MySQLdb
没有报错就可以了。。。。。。。。