I am running 2 Raspberry Pi3 (STRETCH, JESSIE) and a web server (PHP5, MySQL, PHPMyadmin, Apache2) on stretch. I have everything working as expected. However, I need to be able to connect to my MySQL from a remote machine to store data, but I can't connect at all. I have gone UP and DOWN the Internet looking for answers and solution and have tried them all. Still, I can't connect to the MySQL Database. I did the following after reading through Raspberry Pi forum.
Logged into mysql and executed the following commands
CREATE USER 'myusername'@'%' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON *.* TO 'myusername'@'%' WITH GRANT OPTION;
Then, I logged out of mysql and I modified my.cnf file as follows; Commented out the following line in that file.
sudo nano /etc/mysql/my.cnf
and commented out #bind-address = 0.0.0.0
My remote machine still can't connect to MySQL database.
However, I did notice something. On the pi that is running the webserver, my program running on it can connect using the ip address of the machine instead of localhost after doing the above steps before it would only connect using localhost. So I naturally assumed that now my program should be able to connect to mysql database from any other devices on the network, but it is not the case.
So, what am I doing wrong.
bind-address
in your config from127.0.0.1
orlocalhost
to0.0.0.0
so that any machine in your LAN can connect to the database? It looks like you've got that piece wrong. – Dougie Jun 8 '20 at 22:31sudo netstat -tlnpu | grep mysql
to see what address it's listening on you should get0.0.0.0:3306
. Then you just need to create a remote user as per stackoverflow.com/a/16288118/3491475 – Dougie Jun 9 '20 at 11:29