pypyodbc icon indicating copy to clipboard operation
pypyodbc copied to clipboard

Mysql连接

Open Hang-shao opened this issue 1 year ago • 1 comments

Development has moved. Please open new issues at https://github.com/pypyodbc/pypyodbc/issues 请问想读取sql文件,connect连接的数据库类型是Mysql,应该怎么写哈?

pypyodbc.lowercase = False  # 是否将字段名转为小写
# conn = pypyodbc.connect(r"Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + filePath + ";Uid=;Pwd=;") 
conn = pypyodbc.connect('DSN=MYSQL' + filePath + ";Uid=;Pwd=;")
cursor = conn.cursor()

Hang-shao avatar Aug 31 '23 07:08 Hang-shao

您需要使用 Mysql 连接器,而不是 ODBC 连接器,您可以使用以下连接器: https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html 这是一个更详细的教程,解释了前面的步骤和其他细节,如果您正在学习,这些细节将非常有用: https://realpython.com/python-mysql/

braian87b avatar Aug 31 '23 14:08 braian87b