简体   繁体   中英

Python MySQLdb can't connect to remote host?

I am connecting to another system's MySQL in our local network. This is what I did:

import MySQLdb

db = MySQLdb.connect('192.168.100.30','nvnew','nvnew','disdb')
cur = db.cursor()

This is the error I got:

super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on '192.168.100.30' (111)")

I have created the user 'nvnew', granted all the privileges, even manually logged in by that user name to test, so i don't know why the error is coming. I searched google and read all the answers still unable to solve this as everywhere, they show this syntax as correct.

I read somewhere to comment the line

bind-address = 127.0.0.1

in /etc/mysql/my.cnf file. I did that but still I am getting the same error. Also, while connecting to remote system's mysql from my system's terminal using.

mysql -h 192.168.100.30 -u nvnew -p

I was unable to get connected to that.

Can you help?

尝试将其绑定到准确的IP 192.168.100.30 (猜测,它是静态地址),而不要注释

bind-address = 192.168.100.30

Did you restart the remote MySQL daemon after editing the configuration?

(You can use netstat -ltpn to find out if it's listening on 127.0.0.1 or 0.0.0.0.)

Also, be sure you understand the implications of having MySQL bind to all addresses instead of 127.0.0.1 only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM