python3 驱动 PyMySQL

Python版本: 3.5.0

MySqlDB官网只支持Python3.4,  使用第三方库PyMysql连接Mysql数据库。

https://pypi.python.org/pypi/PyMySQL#downloads  

  import pymysql

# change root password to yours:
conn = pymysql.connect(host='localhost', port=3306,user='root',passwd='123456',db='world',charset='UTF8')
cursor = conn.cursor()



=================================================================================
python 3.4以下使用mysql 提供驱动
http://dev.mysql.com/downloads/connector/python/2.0.html

# install mysql-connector-python:
# pip3 install mysql-connector-python --allow-external mysql-connector-python


IMPORT mysql.connector

# change root password to yours:
conn = mysql.connector.connect(USER='root', PASSWORD='password', DATABASE='test')

原文地址:https://www.cnblogs.com/gym333/p/7491572.html