时间:2021-07-01 10:21:17 帮助过:23人阅读
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‘)
python3 驱动 PyMySQL
标签:mysql数据库 oca ldb htm connect host import extern 连接