2 Raspberry PI connecting to same MYSQL database

Thread Starter

zazas321

Joined Nov 29, 2015
856
Hello. I have 2 raspberry PI that I program using python. Main raspberry PI has created mysql database using phpmyadmin and I can access it using localhost/phpmyadmin on the browser.

I put some information there and I want to be able to read/write and do other operations with the information on my secondary Raspberry PI.

Both Raspberry PI's are connected to the same network, however, I cannot access the mysql database on my 2nd PI by trying to connect to the IP address of the first Raspberry PI

For example, the Raspberry PI ip address that is hosting MYSQL database is 192.168.61.170

On my secondary raspberry PI, I am trying to connect in browser : 192.168.61.170/phpmyadmin but it says that it is unreachable.

Why would that be the case if we are both on the same network? Do I need to change some settings?
Keep in mind that I do not want to accept external connections (outside the network) since that would cause some safety problems, I just want to acccept all connections that come from the same network
 
Last edited:
I have never tried phpmyadmin so I can't say if there is something else or not. I do however remember a major stumbling block my first time trying to figure out MySQL.

You have to create a separate user and grant permissions for each client host and user. Normally you would have
Code:
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
In order to connect remotely you would also need
Code:
CREATE USER 'user'@'client Pi IP' IDENTIFIED BY 'password';
You would then grant user@client the necessary permissions to create, modify, admin, and whatever else.

If you have already made it this far then never mind.
 

djsfantasi

Joined Apr 11, 2010
7,689
Where is the problem? Is it MySQL? Or is it in the network?

Can you Ping 192.168.1.170 from the second Pi? If not, it’s a network problem. The “unreachable” error message suggests this case.

Try checking network connectivity first...
 

nsaspook

Joined Aug 27, 2009
8,382
Hello. I have 2 raspberry PI that I program using python. Main raspberry PI has created mysql database using phpmyadmin and I can access it using localhost/phpmyadmin on the browser.

I put some information there and I want to be able to read/write and do other operations with the information on my secondary Raspberry PI.

Both Raspberry PI's are connected to the same network, however, I cannot access the mysql database on my 2nd PI by trying to connect to the IP address of the first Raspberry PI

For example, the Raspberry PI ip address that is hosting MYSQL database is 192.168.61.170

On my secondary raspberry PI, I am trying to connect in browser : 192.168.61.170/phpmyadmin but it says that it is unreachable.

Why would that be the case if we are both on the same network? Do I need to change some settings?
Keep in mind that I do not want to accept external connections (outside the network) since that would cause some safety problems, I just want to acccept all connections that come from the same network
Check to be sure the mysqld server config file has the daemon connected to the actual network port. In some versions the default is to the local socket device for security.

A example of a config section from one of my MSQL servers.
# * Basic Settings
#
user = mysql
pid-file = /run/mysqld/mysqld.pid
socket = /run/mysqld/mysqld.sock
#port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
#skip-external-locking

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = x.x.x.x
Set bind-address to the ip address of the server machine.

https://howtoraspberrypi.com/enable-mysql-remote-connection-raspberry-pi/
Configure MySQL to accept external connections to Raspberry Pi
Now that the rights have been given, we will have to tell to MySQL that we want to accept external connections to the Raspberry Pi.
To do this, we will edit the MySQL configuration file located in the “/etc/mysql” folder:

sudo nano /etc/mysql/my.cnf
We just have to comment the line bind-address, to comment the line add a ‘#’ to the beginning of it, like this:

#bind-address = 127.0.0.1
By default, MySQL is listening only to local connections (127.0.0.1). Commenting this line makes it possible to delete this security and thus, to recover the external connections!
To apply these changes, restart MySQL with the following line:

/etc/init.d/mysql restart
 

nsaspook

Joined Aug 27, 2009
8,382
According to https://raspberry-projects.com/pi/software_utilities/web-servers/mysql the PI does restrict connections to localhost by default. It's been over 15 years since I've done anything with MySQL.

It does also list some commands for setting up remote user access so at least that hasn't changed
Mysql is cool stuff. For larger embedded projects a msyql database can be used with a (Table based) Finite State Machine to manage the all variables needed for sub-millisecond state updates of thousands of state factors.
 

Thread Starter

zazas321

Joined Nov 29, 2015
856
Thank you all for the responses. I have tried djsfantasi suggestion and pinged between two Raspberry machines. Pining return me an error that the host is not reachable, so it definately is some network problem. I have tried to connect to a different wifi network and it worked without any problems. Il have to see and change my network settings and allow connection between the devices
 
Top