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(