Raspberry Pi3 Mysql Python错误 [英] Raspberry pi3 Mysql Python ERROR

查看:120
本文介绍了Raspberry Pi3 Mysql Python错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从python连接到MySQL,但由于以下错误,我显然无法连接.我尝试过这个...

Hi I'm trying to connect from python to MySQL but I can't apparently due to below error. I tried it with this...

import MySQLdb
cnx = MySQLdb.connect(user     ='phpmyadmin',
                      passwd   ='raspberry', 
                      host     ='192.168.0.58',
                      database ='freddy')

print 'connected'
cnx.close()

,然后我将"Mysqldb"更改为"Mysql.connector",但不起作用.这是显示错误:

and then i changed "Mysqldb" to "Mysql.connector" but doesnt work. This is the error showing :

回溯(最近通话最近): 在第2行的文件"test.py"中 cnx = MySQLdb.connect(user ='phpmyadmin',passwd ='raspberry',host ='192.168.0.58',database ='freddy') Connect中的文件"/usr/lib/python2.7/dist-packages/MySQLdb/init.py",第81行 返回Connection(* args,** kwargs) init 中的文件"/usr/lib/python2.7/dist-packages/MySQLdb/connections.py",第204行 超级(连接,自我). init (* args,** kwargs2) TypeError:数据库"是此函数的无效关键字参数 ....

Traceback (most recent call last): File "test.py", line 2, in cnx = MySQLdb.connect(user='phpmyadmin',passwd='raspberry',host='192.168.0.58',database='freddy') File "/usr/lib/python2.7/dist-packages/MySQLdb/init.py", line 81, in Connect return Connection(*args, **kwargs) File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 204, in init super(Connection, self).init(*args, **kwargs2) TypeError: 'database' is an invalid keyword argument for this function ....

我该怎么办?我知道我的密码还可以,但是必须是其他密码...

what should i do? i know my password its fine, but must be somethig else...

推荐答案

单词database应为db,然后应该可以连接.

The word database should be db and then you should be fine and connect.

将您的loginpart更改为以下代码:

Change your loginpart into below code:

cnx = MySQLdb.connect(user   ='phpmyadmin',
                      passwd ='raspberry', 
                      host   ='192.168.0.58',
                      db     ='freddy')

这使您可以监督使用的键和值.享受;-)

This gives you oversight of used keys and values. Enjoy ;-)

这篇关于Raspberry Pi3 Mysql Python错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆