安装mysql(mac环境)
brew install mysql
安装pip(python package管理工具)
sudo easy_install pip
如果没有easy_install,CentOS安装:
curl -O https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
安装MySQL-python
pip install MySQL-python
fatal error: python.h 报错
“_mysql.c:29:20: fatal error: python.h: no such file or directory”
原因是没有安装python-dev
CentOS: sudo yum install python-devel
Ubuntu等:sudo apt-get install python-dev
library not loaded 报错
如 library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib
google之,一般是MySQL-python没配套好, 可以重装:
pip uninstall MySQL-python
pip install MySQL-python
完成以上步骤,python中就可以 import MySQLdb了。下面是查询的code example,增删改生效要 conn.commit()
code example
import MySQLdb文章来源:https://www.toymoban.com/news/detail-455515.html
conn = MySQLdb.connect(
host=‘10.0.64.20’,
port=3文章来源地址https://www.toymoban.com/news/detail-455515.html
到了这里,关于mac python连接mysql的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!