Oct-11-2021, 10:34 PM
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.
Check if you like:
When you create a user on mysql as root, it looks something like this, also when you do it via ssh on the server:
If you want remote access, you need to change the user data (or make a new, remote user):
% here apparently represents any ip
Then on the also via ssh on the server (Ubuntu uses nano mostly, there are other editors):
find the line that has
change this to
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):
After that, my Python data collector using pymysql worked fine from the Idle shell.
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.