mysql Ver 14.14 Distrib 5.5.53, for debian-linux-gnu (x86_64) using readline 6.2
二,Python for Mysql driver 介绍
对于Python而言,有很多访问Mysql的驱动,主要是Mysqldb、mysqlconnector 和 pymysql(参考这篇文章)
MySQL-python: This package contains the MySQLdb module, which is written in C.
It is one of the most commonly used Python packages for MySQL.
mysql-connector-python: This package contains the mysql.connector module, which is written entirely in Python.
PyMySQL: This package contains the pymysql module, which is written entirely in Python. It is designed to be a drop-in replacement for the MySQL-python package.
三,本地环境安装MySQL Connector/Python
在MySQL Connector/Python官网下载:mysql-connector-python-2.1.7-py3.4-windows-x86-64bit.msi 双击安装成功。
cmd命令行下执行 import mysql.connector 成功,如下图:
安装 mysql-connector-python 成功。参考:how do i get mysql to work with python 3.6 in anaconda ide (spyder)?
于是,开始欢喜满满地去测试是否能成功地连接数据库。
打开PyCharm,在菜单栏“Tools”--->“Python console”打开Python Console:
sqlalchemy.exc.InterfaceError: (mysql.connector.errors.InterfaceError) Failed parsing handshake; end byte not present in buffer
网上搜了一下,说是Bug,错误无法解决,参考这里。如能解决,请留言告知,感激不尽。
于是,尝试安装MySQLdb。参考了这篇文章,执行:conda install mysql-python,结果报错:The following specifications were found to be in conflict
说是MySQLdb不支持Python3.6版本。具体可参考这篇文章,于是又只得放弃。
The mysql-python conda package hasn't been built for python 3 .
You can try creating a python 2.7 environment and install mysql-python into that.
再尝试:PyMysql,PyMysql项目的目标是替换MySQLdb
This package contains a pure-Python MySQL client library.
The goal of PyMySQL is to be a drop-in replacement for MySQLdb and work on CPython, PyPy and IronPython.
在Anaconda Prompt中执行:conda install -c anaconda pymysql ,参考:这里