I tried to access data from mysql database through python then I tried as
import MySQLdb
db = MySQLdb.connect(host = "127.0.0.1",
port = 3306,
user="Bishnu",
password = "Pulchowk",
db = "telecom_db")
cursor =db.cursor()
cursor.execute("select * from profile")
numrows = int(cursor.rowcount)
for x in range(numrows):
row = cursor.fetchone()
#if (row):
print row[0], row[1]
cursor.close()
db.cose()
then it shows error
Traceback (most recent call last):
File "D:\Bishnu\BE4円th year7円th semester\Major Project I\Workspace\Bishnuji\default\first.py", line 43, in <module>
db = "telecom_db")
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
TypeError: 'password' is an invalid keyword argument for this function
Then I also tried removing password as
import MySQLdb
db = MySQLdb.connect(host = "127.0.0.1",
port = 3306,
user="Bishnu",
#password = "Pulchowk",
db = "telecom_db")
cursor =db.cursor()
cursor.execute("select * from profile")
numrows = int(cursor.rowcount)
for x in range(numrows):
row = cursor.fetchone()
#if (row):
print row[0], row[1]
cursor.close()
db.cose()
still it shows error
Traceback (most recent call last):
File "D:\Bishnu\BE4円th year7円th semester\Major Project I\Workspace\Bishnuji\default\first.py", line 43, in <module>
db = "telecom_db")
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1044, "Access denied for user ''@'localhost' to database 'telecom_db'")
What may be the solution ?
3 Answers 3
from the documentation seems that the correct naming of the parameter is passwd
2 Comments
Check whether you have set password on your database or not. Normally user name and password are not changed and Default user name = 'root' and password filled is null i.e password = ''. If you have set password and forgot it then you can retrieve it by following instruction stated at How do I retrieve my MySQL username and password?
Comments
Please uninstall and again install the mysqlclient using commands for uninstall
pip uninstall mysqlclient
for install
pip install mysqlclient