1
votes

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()

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

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...

1
Finish the tour and check in a bit how I reformatted your question to fit the requirements of SO.ZF007
im using rasbian.Freddy Alex Saavedra
If one of the provided answers worked for you please select it as best answer and upvote it.ZF007

1 Answers

0
votes

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

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 ;-)