Lasse Bendiksen
Lasse Bendiksen

Reputation: 221

ERROR 2002 (HY000): Can't connect to MySQL server on '192.168.1.15' (115)

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

Upvotes: 22

Views: 98641

Answers (7)

Muayyat Billah
Muayyat Billah

Reputation: 25

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

Upvotes: -1

Marcelo P. Llanos C.
Marcelo P. Llanos C.

Reputation: 107

  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'

Upvotes: -1

theking2
theking2

Reputation: 2803

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.

Upvotes: 1

Georg Richter
Georg Richter

Reputation: 7476

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.

Upvotes: 6

Aurangzeb
Aurangzeb

Reputation: 1626

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

Upvotes: 1

sb3849
sb3849

Reputation: 211

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

Upvotes: 21

Bahadır Birsöz
Bahadır Birsöz

Reputation: 181

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.

Upvotes: 1

Related Questions