python 3.5.2安装mysql驱动报错
2016-08-12 16:02
302 查看
python 3.5.2安装mysql驱动报错
python 3.5.2安装mysql驱动时出现如下异常:[root@localhost www]# pip install mysql-connector-python Collecting mysql-connector-python Could not find a version that satisfies the requirement mysql-connector-python (from versions: ) No matching distribution found for mysql-connector-python
这是由于官方驱动暂时只支持到python3.4所致。改用
pymysql
安装pymysql
pip install PyMySQL
使用例子:
建表语句
CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `email` varchar(255) COLLATE utf8_bin NOT NULL, `password` varchar(255) COLLATE utf8_bin NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;
import pymysql.cursors # Connect to the database connection = pymysql.connect(host='localhost', user='user', password='passwd', db='db', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) try: with connection.cursor() as cursor: # Create a new record sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)" cursor.execute(sql, ('webmaster@python.org', 'very-secret')) # connection is not autocommit by default. So you must commit to save # your changes. connection.commit() with connection.cursor() as cursor: # Read a single record sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s" cursor.execute(sql, ('webmaster@python.org',)) result = cursor.fetchone() print(result) finally: connection.close()
参考文档
https://pypi.python.org/pypi/PyMySQL#example
相关文章推荐
- windows7 64位下Python2.7安装MySQL驱动遇到的问题
- Python安装Mysql驱动出错解决(最新出炉)
- python安装MySQL和驱动
- 在没有root权限的测试机上安装MySQL-Python驱动
- python2.7安装mysql的数据驱动
- python2.7安装mysql驱动
- Python安装MySQL驱动出错
- windows下安装mysql驱动mysql-python
- Ubuntu 16.04 - python3 安装mysql驱动
- Mac 安装mysql以及python驱动
- MySql :windows python 安装mysql驱动,从sql脚本恢复数据库,删除表
- python3.x+django的mysql驱动安装问题
- windos平台anoconda下python安装mysql驱动出错
- python安装mysql驱动遇到的问题
- windows安装python的mysql驱动mysql-connector-python
- macOS系统 安装MySQL-python驱动方法
- Python下安装MySQL驱动出错
- mysql-connector-pythonl驱动安装
- linux下安装python mysql驱动
- python mysql驱动安装过程中遇到的问题