我是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'
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)")