1、下載Mysql官方connector驅動
地址:https://dev.mysql.com/downloads/connector/python/
根據提示安裝.dmg文件便可。
2、驗證是否安裝成功html
shell> python
>>> from distutils.sysconfig import get_python_lib >>> print get_python_lib() # Python v2.x /Library/Python/2.7/site-packages >>> print(get_python_lib()) # Python v3.x /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages
3、使用示例代碼測試鏈接數據庫python
import mysql.connector
cnx = mysql.connector.connect(user='scott', password='tiger', host='127.0.0.1', database='employees') cnx.close()
也可以使用以下命令測試是否安裝成功:mysql
~ python
>>> import mysql.connector as mc >>> mc.__version__ '2.1.6'
更多使用方式可訪問官方網站:
https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.htmlsql
4、其它驅動鏈接方式
1.MySQL-Python(或者說MySQLdb)相關連接
http://blog.csdn.net/zhaoteng345/article/details/52165914
http://blog.csdn.net/janronehoo/article/details/25207825
https://www.zhihu.com/question/30963225
https://www.runoob.com/python/python-mysql.html
2. Python中最鏈接Mysql經常使用的驅動是shell
mysql-python :mysql的C語言的驅動
mysql-connector:msql官方的驅動
pymysql:python語言的驅動數據庫