因此,我很难使用python mysql.connector模块连接到本地数据库。

因此,我试图使用突出显示的连接进行连接。我使用密码abcdefghijkl登录到SQL环境。我正在尝试连接到一个名为flight_school的数据库。
我的python脚本看起来是这样的。
import mysql.connector
mydb = mysql.connector.connect("localhost", "root", "abcdefghijkl", "flight_school")
print(mydb.is_connected())上述代码按以下顺序排列在参数中,即
只是不起作用。我得到以下错误。

请给我一些建议。
发布于 2020-04-30 00:15:11
请始终阅读官方的文档
你必须有这个表格(如果你这样做的话,这个way= )
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="testpaaword",
database="testdb"
)发布于 2020-04-30 00:14:52
查看SQL-炼金术模块,从我的经验中产生奇迹。
发布于 2022-11-17 10:28:15
请始终阅读官方文件:https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html
import mysql.connector
from mysql.connector import errorcode, MySQLConnection
try:
db_connection = MySQLConnection(user='root', password='', port='3306', database='your_database')
print("Database connection made!")
except mysql.connector.Error as error:
if error.errno == errorcode.ER_BAD_DB_ERROR:
print("Database doesn't exist")
elif error.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("User name or password is wrong")
else:
print(error)
else:
db_connection.close()
cursor = db_connection.cursor()
sql = ("commands")
cursor.execute(sql)https://stackoverflow.com/questions/61513711
复制相似问题