17

I'm trying to make a MySQL database on my Raspberry Pi 4, but it isn't going very well, using localhost instead works perfectly but I want to remote control it from my Windows 10 computer on the same internet. When I create a user with the address of 192.168.1.15 by doing this:

sudo mysql -u root
CREATE USER 'lasse'@'192.168.1.15' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'lasse'@'192.168.1.15';
FLUSH PRIVILEGES
exit

I try to login again using this:

mysql -u lasse -h 192.168.1.15 -ppassword // didnt work, error: ERROR 2002 (HY000): Can't connect to MySQL server on '192.168.1.15' (115)
mysql -u user -h 192.168.1.2 -P 3306 -ppassword // didnt work either, same error.

I have these packages installed:

mariadb-client
mariadb-server
default-mysql-server
3

6 Answers 6

14

In the file /etc/mysql/mariadb.conf.d/50-server.cnf (Raspi-os 2021-03-04 with MariaDB installed), you should replace the line "bind-address = 127.0.0.1" (localhost) by "bind-address = 0.0.0.0" (all). After, you should restart your MySQL server : $ sudo service mariadb restart

2
  • does not work. might be firewall blocked.
    – chans
    Jan 28, 2022 at 2:44
  • "Failed to restart mariadb.service: Unit mariadb.service not found." Dec 9, 2022 at 23:07
2

Error 115 is returned from socket operation (EINPROGRESS), which means that your client can't physically connect to the specified server and port.

The MariaDB database server is not configured correctly, since it doesn't accept remote connections. Please login locally and check the following variables:

SHOW VARIABLES LIKE 'skip_networking' (result should be off)
SHOW VARIABLES LIKE 'bind-address' (should not be 127.0.0.1)

Since these are read only variables, you need to change them (or comment them out with a #) in your my.cnf configuration file.

2
  • How do you know what error 115 means? Please link to resource table if possible Apr 27, 2021 at 12:08
  • 1
    Either check errno.h or use perror command. Apr 27, 2021 at 16:09
1

ERROR 2002 is "Can't connect" error. Check out /etc/my.cnf, look for listen line. It may be listening localhost or 127.0.0.1. You need to change it to listen 0.0.0.0.

0
1

There are three things

  1. You need to set the bind-address to 0.0.0.0 (or 192.168.1.15 to be exact and specific)
  2. You might need to set the firewall to allow port 3306 ( or iptables --flush as shortcut )
  3. You need to create a global user (root@'%') in the mysql database or some user like 'root@192.168.1.15' with a password

when all conditions are fulfilled, you should be able to connect to mysql database on 192.168.1.15

1

What is most likely the case is that the server is not listening on port 3306. As in both lines you implicit or explicit use port 3306. As it is the only constant in the two lines most likely the culprit.

The default port for clients is specified in my.ini in the [client] section, the port used by the server is in the [mysqld] section. They don't necessarily have be the same so check both.

To make absolutely sure what is going on the server — assuming it is linux — use this to list all listening ports:

sudo netstat -tnlp

There, saved you a walk to the docs.

0
  1. Login to the MariaDb server and edit the file /etc/mysql/my.cnf
  2. Edit the row bind-address=YOUR_SERVER_IP
  3. Restart the server using '/etc/init.d/mariadb restart' or 'systemctl restart mariadb.service'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.