Xerphiel
Xerphiel

Reputation: 1133

Python and MySQLDB connection to another server on the network

I am writing a Python app that runs on my windows machine and I am trying to connect to my MySQL server on a linux box. I've had no trouble writing code locally on my linux box in python and connecting to the MySQL db, but when I try and connect over my local network it fails.

db = MySQLdb.connect(host="192.168.0.100", user="root", passwd="password", db="db")

I get:

_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on '192.168.0.100' (10061)")

Any thoughts on how I can achieve this?

Upvotes: 1

Views: 4008

Answers (1)

Rob Wouters
Rob Wouters

Reputation: 16327

This is likely a MySQL configuration issue.

Make sure MySQL is listening on 192.168.0.100 (or 0.0.0.0) and not on 127.0.0.1. Do this by setting the bind-address option.

For security considerations, instead of using root, it is recommended to create a separate user to connect remotely with. Then grant it access from a specific IP(-range): GRANT ... TO username@'192.168.0.%', assuming your local IP is in 192.168.0.0/24.

One other thing to check is to make sure your firewall allows access to/from port 3306.

Upvotes: 2

Related Questions