MySQL connection issue in Python app with non-admin account

I’m having trouble with my Python Windows application. I set up two MySQL accounts: an admin and a regular user. The app works fine locally, but I can’t connect using the public IP address with the user account.

When I try to run it in VS Code, I get this error:

pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '[IP]' (timed out)")

I’ve already added bind-address: 0.0.0.0 to my.ini file. What am I missing? How can I make this work on other computers?

I’m new to database connections, so any help would be great. Thanks!

Hey CreatingStone, I’ve been through this headache before. Sounds like you’ve got the basics covered with the bind-address, but there’s a few more things to check.

First, make sure your MySQL server is actually listening on the public IP. You can verify this by running ‘netstat -an | findstr 3306’ in CMD on your server.

Also, check if your hosting provider or firewall is blocking incoming connections. Sometimes they have default rules that need tweaking.

One thing that tripped me up was forgetting to update my connection string in the Python code. Make sure it’s using the public IP, not localhost.

Lastly, try connecting with a MySQL client from another machine. If that works, the issue might be in your Python code or dependencies.

Keep at it, and don’t hesitate to post your connection code (minus sensitive info) if you’re still stuck!

hey there! sounds like a firewall issue. check if port 3306 is open on ur server. also, make sure the user account has proper permissions to connect from remote IPs. u might need to update the user’s host in MySQL to allow connections from ‘%’. good luck!

I encountered a similar issue when setting up remote access for my MySQL database. First, ensure your MySQL server is configured to accept remote connections. Check your my.cnf or my.ini file for the ‘skip-networking’ directive and comment it out if present. Also, verify that the user account has the correct privileges for remote access. You can grant these with:

GRANT ALL PRIVILEGES ON database_name.* TO ‘username’@‘%’ IDENTIFIED BY ‘password’;
FLUSH PRIVILEGES;

Replace ‘database_name’, ‘username’, and ‘password’ with your specific details. Finally, double-check your firewall settings on both the server and client sides. Sometimes, antivirus software can also interfere with database connections.