Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm having problems connecting to a MySQL server on a Raspberry Pi from Windows using PHP.

What I've done:

On the pi:
iptables -I INPUT -j ACCEPT


The pi and PC are on the same network.

The code I'm using is able to connect to other servers just fine. Only been able to test servers outside of this network.

I'm able to log in with the same credentials I'm using in the PHP file, using adminer on the pi.

The user I'm trying to log in with has all permissions to the table from '%' ip address.

Both machines are able to ping each other.


Any help would be appreciated.

What I have tried:

Everything mentioned in the question, searching online to no avail.
Posted
Updated 28-May-20 19:18pm
v2
Comments
Christiaan van Bergen 4-Apr-18 17:51pm    
Have you used the "flush privileges;" for the changes to take effect?
[no name] 4-Apr-18 17:52pm    
Yes, and that's why I'm able to make use of the database just fine in adminer using the same user
Christiaan van Bergen 4-Apr-18 18:05pm    
So everything works, but remote. Any other firewall or netfilter running on the pi? Check the running processes. Run a check on the open ports and programs:
$ netstat --tcp --listening --programs --numeric
[no name] 4-Apr-18 18:06pm    
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 503/mysqld
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 355/sshd
tcp6 0 0 :::80 :::* LISTEN 483/apache2
tcp6 0 0 :::22 :::* LISTEN 355/sshd
[no name] 4-Apr-18 18:06pm    
I can even access the web server on the pi from this pc, just not mysql

The MySQL server on the Pi is probably not listening on the network interface. For security reasons the default is listening on the loopback / local host / 127.0.0.1 interface only.

The common location of the MySQL configuration file is /etc/mysql/my.cnf. If that contains a line
bind-address     127.0.0.1
comment that out or change it to
bind-address     0.0.0.0
 
Share this answer
 
Comments
[no name] 4-Apr-18 18:17pm    
That file doesn't contain that line, only:

[client-server]
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
Jochen Arndt 4-Apr-18 18:21pm    
Then look for the my.cnf file in those directories.
The option will be in the [mysqld] section.
[no name] 4-Apr-18 18:18pm    
Ah perfect, found it.
For others to see, the solution was this;

Change bind-address to 0.0.0.0 in:
/etc/mysql/mariadb.conf.d/50-server.cnf
 
Share this answer
 
In your mysql config /etc/mysql/my.conf comment out the following line:
bind-address=
When you do that, it will bind to all addresses. Also make sure that you don't have skip-networking enabled in your my.cnf.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900