1

我在使用Anaconda Spyder IDE时遇到了python 2.7的mysql连接器问题。虽然下面的代码在Python Gui中起作用,但我在spyder中出现以下错误:'ImportError:No Module named mysql.connector'。spyder mysql连接器python

下面是代码:

import mysql.connector 
conn=mysql.connector.connect(user='root',password='xxxxx',host='localhost',database='xxxxx') 
mycursor=conn.cursor() 

mycursor.execute("""SELECT Ir FROM FinProg where ProgCatId = 4""") 
obrrate = mycursor.fetchall(). 

我经由与此命令行上spyder的下载的MySQL连接器: '康达安装mysql-蟒'。

spyder是否需要不同的语法来使用mysql-connector?我如何使用spyder的mysql连接器?

回答

1

好的,我在spyder中使用了不同的代码语法,它终于有效。这里是spyder python 2.7中的成功代码: import mysqldb conn = MySQLdb.connect(host ='localhost',user ='root',passwd ='xxxxx',db ='xxxxx') mycursor = conn.cursor ()

1

你使用MySQLdb的可能是工作就好了你,但澄清的解决方案:

MySQLdb的和MySQL.Connector是为MySQL和Python两个不同的端口。您的问题中的代码似乎是MySQL.Connector的有效语法,其中Spyder通过安装

conda安装mysql-connector-python