java多线程    Java入门    vsftp    ftp    linux配置    centos    FRP教程    HBase    Html5缓存    webp    zabbix    分布式    neo4j图数据库    

python3.9 安装mysql

pip install mysqlclient==2.1.1

NameError: name '_mysql' is not defined

有人说版本高了

pip install mysqlclient==1.4.6

symbol not found in flat namespace '_mysql_affected_rows'

pip install mysql-Python 报错 ModuleNotFoundError: No module named 'ConfigParser'

pip -V
pip 21.2.4 from /Users/ge/opt/anaconda3/lib/python3.9/site-packages/pip (python 3.9)

cd /Users/ge/opt/anaconda3/lib/python3.9/

mv configparser.py ConfigParser.py

ModuleNotFoundError: No module named 'configparser'

改回来 mv ConfigParser.py configparser.py

换pymysql

 pip install PyMySQL
import pymysql

# 打开数据库连接
db = pymysql.connect(host='localhost',
                     user='testuser',
                     password='test123',
                     database='TESTDB')

# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()

# 使用 execute()  方法执行 SQL 查询 
cursor.execute("SELECT VERSION()")

# 使用 fetchone() 方法获取单条数据.
data = cursor.fetchone()

print ("Database version : %s " % data)

# 关闭数据库连接
db.close()


This entry was posted in Python and tagged , . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/python3-9-install-mysql/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力.

2 Responses to python3.9 安装mysql

  1. 默默 says:

    你好,贵站友情链接中,本站原名为:徐志摩文集 http://www.cadps.com。现在已更改为:技术日志 https://www.cadps.net ,望贵站给予更改。

Leave a Reply to 默默 Cancel reply