LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-20-2018, 03:56 PM   #1
andrew2110
LQ Newbie
 
Registered: Dec 2009
Posts: 6

Rep: Reputation: 0
ERROR 2003 (HY000): Can't connect to MySQL server on 'ip-address' (111)


Hello!

The internets got a lot of help for this error I've been having so have been able to try quite a few steps but am still at a loss so here we are. The issue is I can't connect to my mysql server from a remote IP address.

Steps taken so far

1. make sure bind address is set to 0.0.0.0 in /etc/mysql/mysql.conf.d/mysqld.cnf
2. make sure port 3306 is open and accessible on the server (https://www.yougetsignal.com/tools/open-ports/ says (80.0.21.46 is accessible on port 3306)
3. Forward port 3306 from the router to the ip address of the server in my LAN:

http://80.0.21.46/portforwarding.png

4. Make sure that the user I'm connecting as to mysql has privileges to access from remote IP addresses:

+---------------------------------------------------------------+
| Grants for myusername@% |
+---------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'myusername'@'%' WITH GRANT OPTION |
+---------------------------------------------------------------+



Whilst on the local area network, I can telnet into the machine on port 3306 using the public IP address, however when I try it from a machine outside of the local area network I get the can't connect to mysql server and am not too sure what to try next.
 
Old 08-21-2018, 05:50 AM   #2
andrew2110
LQ Newbie
 
Registered: Dec 2009
Posts: 6

Original Poster
Rep: Reputation: 0
An update to this, when connecting from a different remote server, it actually allows it to connect which leads me to believe that my machine is just blocking the IP address of my main server. I'm running elementary OS and am not sure at all where to find whether this is the case or not. The firewall is turned off in settings and I've tried removing all rules from iptables. There's no chance that on my remote server its just blocking me trying to connect to mysql on my home server is there?
 
Old 08-21-2018, 08:55 AM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Connects from here:
Code:
telnet 80.0.21.46 3306
Trying 80.0.21.46...
Connected to 80.0.21.46.
Escape character is '^]'.
[
5.7.23-0ubuntu0.16.04.1tF:1u|@ T8jumysql_native_passwordConnection closed by foreign host.

Last edited by Habitual; 08-21-2018 at 08:58 AM.
 
Old 08-21-2018, 09:13 AM   #4
andrew2110
LQ Newbie
 
Registered: Dec 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Thank you, my main server blocking any data transfer on 3306 is what has turned out to be the issue here. I've opened that port on the server and now I can access the home server from it
 
Old 08-21-2018, 06:29 PM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by andrew2110 View Post
Code:
GRANT ALL PRIVILEGES ON *.* TO 'myusername'@'%' WITH GRANT OPTION
I can't begin to tell you of the inherent risks associated with wildcard hosts in a grant statement such as yours.
Literally, anyone w\your username and password can access your db without restriction, from any host ('%')
Quote:
Originally Posted by andrew2110 View Post
I've opened that port on the server
If your home system is the workhorse, and that is where you'll connect from,
get your forward-facing IP and use that in your grant statement. That is my suggestion.

whatismyip.com or 100 others. Let's assume yours comes back with
121.212.112.221

The grant statement to allow your computer from "home" is
Code:
GRANT ALL PRIVILEGES ON *.* TO 'myusername'@'121.212.112.221' WITH GRANT OPTION ;
and some ufw goodness:
Code:
ufw deny 3306
ufw INSERT 1 allow from 121.212.112.221 to any port 3306
Scans via nmap come back as "Filtered", except if the nmap port scan comes from 121.212.112.221 in which case it will say OPEN
And you should be better "set"
Good Luck.

Last edited by Habitual; 08-21-2018 at 06:34 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR 2002 (HY000): Can't connect to local MySQL server through socket tiroloz Linux - Software 4 05-05-2012 10:15 AM
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/my.. Goce Linux - Server 3 11-30-2008 10:57 PM
Yet another mysql ERROR 2003 (HY000): Can't connect to MySQL server on REMOTE_HOST ( dan.mk Linux - Networking 2 05-09-2008 01:43 PM
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.so amee_stars Linux - Newbie 2 01-22-2007 03:48 AM
ERROR 2003: Can't connect to MySQL server on '127.0.0.1' (111) eantoranz Ubuntu 4 09-06-2005 03:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration