Python Forum
pysql connection to cloud server database times out
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pysql connection to cloud server database times out
#10
Like bowlofred said, this is not really a Python problem, but without this, pymysql will not work from a remote machine.

Just in case anyone else has this problem, a solution:

This way is probably not so secure, with 3306 open, but a) I only have homework b) you still need the user name and password. There is a more secure way using mysql rsa key encryption I read.

ssh to your cloud server.

First, open port 3306 on the cloud server.

Quote:sudo ufw allow 3306
sudo ufw enable

Check if you like:

Quote:sudo ufw status

When you create a user on mysql as root, it looks something like this, also when you do it via ssh on the server:

Quote:CREATE USER 'peter'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON some_db.* TO 'peter'@'localhost';

If you want remote access, you need to change the user data (or make a new, remote user):

Quote:RENAME USER 'peter'@'localhost' TO 'peter'@'%';
GRANT ALL ON somedb.* TO 'peter'@'%';
FLUSH PRIVILEGES;

% here apparently represents any ip

Then on the also via ssh on the server (Ubuntu uses nano mostly, there are other editors):

Quote:sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

find the line that has

Quote:bind-address = 127.0.0.1

change this to

Quote:bind-address = 0.0.0.0

ctrl X to quit nano, nano asks if you want to save, press y, then enter to save in the same place you opened /etc/mysql/mysql.conf.d/mysqld.cnf

Then (on the server):

Quote:sudo systemctl restart mysql

After that, my Python data collector using pymysql worked fine from the Idle shell.
Reply


Messages In This Thread
RE: pysql connection to cloud server database times out - by Pedroski55 - Oct-11-2021, 10:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Database connection problems [login, PyQt5, PySql] gradlon93 5 838 Dec-15-2023, 05:08 PM
Last Post: deanhystad
  Networking Issues - Python GUI client and server connection always freezes Veritas_Vos_Liberabit24 0 801 Mar-21-2023, 03:18 AM
Last Post: Veritas_Vos_Liberabit24
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,639 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  Serial connection connection issue Joni_Engr 15 8,437 Aug-30-2021, 04:46 PM
Last Post: deanhystad
  How to take the tar backup files form remote server to local server sivareddy 0 1,993 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  ws server exit after getting 1 connection korenron 3 5,565 Feb-04-2021, 07:49 PM
Last Post: nilamo
  run a health check script on cloud server through paramiko amritjsr 4 3,391 Jul-21-2020, 02:30 AM
Last Post: amritjsr
  Connection timed out error when connecting to SQL server kenwatts275 2 3,430 Jun-02-2020, 07:35 PM
Last Post: bowlofred
  Connection DATABASE to Python MenThoLLt 3 2,508 Jan-17-2020, 10:35 PM
Last Post: DT2000
  Unable to login to remote SQL Server database sipriusPT 1 15,190 Dec-20-2019, 10:16 AM
Last Post: sipriusPT

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020