pycharm安装mysql模块

时间:2024-05-30 18:03:21

在pycharm中需要调用mysql数据库,需要加载第三方库。

在搜索中mysql中出现很多选择,见下图

pycharm安装mysql模块

但是这个mysql包一直安装不上,最后可以安装mysql-connector-python

说明:https://pypi.org/project/mysql-connector-python/

这个包中的mysql,是不依赖MySQL数据库的C语言客户端库的,MySQL driver written in Python which does not depend on MySQL C client libraries and implements the DB API v2.0 specification (PEP-249).

引用如下:

# -*- coding: UTF-8 -*-
# python 2.7
import mysql.connector
cnn_mysql = mysql.connector.connect(user='root', passwd='11112018', database='s30sdata')
cursor_mysql = cnn_mysql.cursor()
sql_query = "SELECT sitecode4 FROM hlj_info"