MySQLdb._exceptions.OperationalError:(2005,“未知的MySQL服务器主机“ localhost”(11001)”)

时间:2019-05-08 23:42:33

标签: mysql python-3.x

我是Python的新手,我正在尝试将 MySQL Python 连接。

通过编写此命令:

python C:PATH/learning_to_rank.py 'localhost' 3306 'root' 'dbpsd' 'scheme' 'electricityconsumptionofeasternchina' 'SELECT * FROM electricityconsumptionofeasternchina' 'city' 'date' 'elctConsumption' 'varchar(125)' 'date' 'float'

learning-to-rank.py

dbArgs = sys.argv[1:6]
instance=Instance(sys.argv[6])
instance.addTable(Table(instance,False,'',''))
conn=MySQLdb.connect(host=dbArgs[0],port=int(dbArgs[1]),user=dbArgs[2],passwd=dbArgs[3],db=dbArgs[4],charset='utf8')
cur=conn.cursor()
instance.column_num=instance.tables[0].column_num=(len(sys.argv)-8)/2

该算法的输出应该是 JSON 数据 但我明白了:

Traceback (most recent call last):
  File "C:\PATH/learning_to_rank.py", line 18, in <module>
    conn=MySQLdb.connect(host=dbArgs[0],port=int(dbArgs[1]),user=dbArgs[2],passwd=dbArgs[3],db=dbArgs[4],charset='utf8')
  File "C:\Users\Asus\AppData\Local\Programs\Python\Python37\lib\site-packages\MySQLdb\__init__.py", line 84, in Connect
    return Connection(*args, **kwargs)
  File "C:\Users\Asus\AppData\Local\Programs\Python\Python37\lib\site-packages\MySQLdb\connections.py", line 164, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (2005, "Unknown MySQL server host ''localhost'' (11001)")

0 个答案:

没有答案