Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

mariadb

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
like image 470
Lasse Bendiksen Avatar asked Oct 12 '20 14:10

Lasse Bendiksen


People also ask

How do I fix error 2002 hy000?

To fix this error, you need to see if MySQL server is already installed and running on your computer. That should start the server and generate the mysql. sock file. You can try to connect to your MySQL server again now.

When connecting to MySQL If you get the error error 2002?

The error (2002) Can't connect to ... normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server.

How to troubleshoot MySQL error 2002?

If you see the same status, you can run the service by clicking the Start the service link on the left pane. Now you can try to connect again to your MySQL server from the Command Line. To conclude, the ERROR 2002 happens when your computer can’t connect to MySQL server because the socket file is missing.

How to fix MySQL not connecting to the server?

You can try to connect to your MySQL server again now. If you’re using macOS and installed MySQL using Homebrew, then you need to make sure that the server is started using the following command: Once MySQL is running, you can try to connect using the mysql command again.

Can bobcares help you resolve MySQL error 2002 (hy000)?

We can help you resolve it. Usually, this error occurs if MySQL is not running or if it is not getting connected. At Bobcares, we often get requests from our customers to fix MySQL errors as part of our Server Management Services. Today, let’s get into the details on how our Support Engineers fix this error. Why MySQL error 2002 (hy000) occurs?

Why is my MySQL server not starting up or running?

This file is created when MySQL server is started and removed when you stop the server. To fix this error, you need to see if MySQL server is already installed and running on your computer. If you’re using Linux, you may need to install mysql-server in addition to the mysql package:


Video Answer


4 Answers

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

like image 87
sb3849 Avatar answered Nov 15 '22 03:11

sb3849


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.

like image 26
Bahadır Birsöz Avatar answered Nov 15 '22 04:11

Bahadır Birsöz


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

like image 26
Aurangzeb Avatar answered Nov 15 '22 04:11

Aurangzeb


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.

like image 25
Georg Richter Avatar answered Nov 15 '22 03:11

Georg Richter