문제

I'm trying to connect to my sql server using a simple python script.

import MySQLdb

db = MySQLdb.connect(host="192.168.0.156", user="root",
passwd="Imnottellingyoumypassword", db="mydatabase") # name of the data base

cur = db.cursor() 
cur.execute("SELECT * FROM customers")

for row in cur.fetchall() :
    print row[0]

But when I run my script something goes wrong:

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 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 
'root'@'192.168.0.107' (using password: YES)")

Why is he trying to connect to my ip address of my laptop instead of the sql server?

도움이 되었습니까?

해결책

That message is from the MySQL server and not the MySQL driver. What the server is telling you is that connections as root from the IP of your laptop aren't allowed.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top