我的开发环境
python3.8 mariadb 5.5.52 pymysql 1.0.2 django 4.1.3
尝试迁移,但是vscode提示django.db.utils.NotSupportedError: MariaDB 10.3或更高版本是必需的(查找5.5.52)。
发布于 2022-12-03 07:08:56
要使用Python3连接到MariaDB 5.5.52数据库,可以使用pymysql库。这个库提供了一个Python接口,用于连接和使用MariaDB数据库。
要使用pymysql,首先需要使用pip安装它。
pip install pymysql一旦安装了pymysql,就可以通过导入pymysql模块并创建一个新的MariaDB对象来连接到您的Connection数据库,如下所示:
import pymysql
# Connect to the database
conn = pymysql.connect(
host="localhost",
user="username",
password="password",
db="database_name"
)
# Use the cursor() method to create a cursor object
cur = conn.cursor()
# Execute a SQL query
cur.execute("SELECT * FROM table_name")
# Fetch the results of the query
results = cur.fetchall()
# Print the results
print(results)至于从Django看到的错误消息,听起来您使用的是与MariaDB 5.5.52不兼容的Django版本。Django 4.1.3需要MariaDB 10.3或更高版本,因此您需要将MariaDB安装升级到更新的版本,以便使用Django 4.1.3。或者,您可以尝试使用与MariaDB 5.5.52兼容的较早版本的Django。
https://stackoverflow.com/questions/74664116
复制相似问题