ERROR 2002 (HY000): Can't connect to MySQL server on '192.168.1.15' (115) [closed]
Asked Answered
J

7

22

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
Jerry answered 12/10, 2020 at 14:49 Comment(3)
Have a read through dev.mysql.com/doc/refman/8.0/en/can-not-connect-to-server.htmlJointure
I'd expect there are existing answers over at Database Administrators.Hoarse
packages installed: […] mariadb-server default-mysql-server It wouldn't hurt to mention which server listens to which port for connections from where. Think twice before allowing from everywhere.Drawer
P
21

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

Poteat answered 23/4, 2021 at 6:0 Comment(2)
does not work. might be firewall blocked.Tella
"Failed to restart mariadb.service: Unit mariadb.service not found."Amaryllidaceous
K
6

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.

Knotting answered 12/10, 2020 at 15:22 Comment(3)
How do you know what error 115 means? Please link to resource table if possiblePlanimeter
Either check errno.h or use perror command.Knotting
For me at some point (presumably after upgrading in Ubuntu), the config's bind-address changed to 127.0.0.1 (localhost), so after setting it back to 0.0.0.0, it works again.Devoirs
M
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.

Massengale answered 12/10, 2020 at 14:54 Comment(1)
On my Ubuntu, it is /etc/mysql/my.cnfDevoirs
B
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 '[email protected]' with a password

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

Bethsaida answered 23/4, 2021 at 7:50 Comment(0)
V
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.

Voiced answered 21/9, 2021 at 19:54 Comment(0)
O
-1
  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'
Ocker answered 23/12, 2021 at 23:33 Comment(0)
T
-1

Look for all occurence of "bind-address" and comment it. In /etc/mysql/ in all the files in that directory and its subs.

Tantalite answered 13/4 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.