ERROR 2003 (HY000): Can't connect to MySQL server on [IP] (111 "Connection refused")

error 2003 (hy000): can't connect to mysql server on (113)
error 2003 (hy000): can't connect to mysql server on '127.0.0.1' (10061)
error 2003 (hy000 can t connect to mysql server on '192.168 13 111)
can't connect to mysql server on (111)
error 2003 (hy000) windows 10
(2003, "can't connect to mysql server on
error 2003 (hy000): can't connect to mysql server on '127.0.0.1' (61) mac
mysqli connect error 2003

I am trying to connect to Server A (Ubuntu 16.04) remotely from Server B (Ubuntu 16.04). I can already use MySQL fine with remote@[Server A IP] on Server A, but I am having trouble accessing that user from Server B. I have gone through the procedure of checking ufw firewalls, configuration files, and the MySQL user, but I cannot seem to find what the issue is. What are possible steps I can go through to provide more information, or is the issue in some information I provided?

Server A with database

Configuration Files

/etc/mysql/my.cnf

# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
[mysqld]
innodb-file-format=barracuda
innodb-file-per-table=1
innodb-large-prefix=1
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

[mysql]
default-character-set = utf8mb4

/etc/mysql/mariadb.cnf

# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
[mysqld]
innodb-file-format=barracuda
innodb-file-per-table=1
innodb-large-prefix=1
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

[mysql]
default-character-set = utf8mb4

/etc/mysql/mariadb.conf.d/50-server.cnf

#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#

# this is read by the standalone daemon and embedded servers
[server]

# this is only for the mysqld standalone daemon
[mysqld]

#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# Bind to all addresses
# bind-address      = 127.0.0.1

#
# * Fine Tuning
#
key_buffer_size     = 16M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10

#
# * Query Cache Configuration
#
query_cache_limit   = 1M
query_cache_size        = 16M

#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Enable the slow query log to see queries with especially long duration
#slow_query_log_file    = /var/log/mysql/mariadb-slow.log
#long_query_time = 10
#log_slow_rate_limit    = 1000
#log_slow_verbosity = query_plan
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id      = 1
#log_bin            = /var/log/mysql/mysql-bin.log
expire_logs_days    = 10
max_binlog_size   = 100M
#binlog_do_db       = include_database_name
#binlog_ignore_db   = include_database_name

#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!

#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

#
# * Character sets
#
# MySQL/MariaDB default is Latin1, but in Debian we rather default to the full
# utf8 4-byte character set. See also client.cnf
#
character-set-server  = utf8mb4
collation-server      = utf8mb4_general_ci

#
# * Unix socket authentication plugin is built-in since 10.0.22-6
#
# Needed so the root database user can authenticate without a password but
# only when running as the unix root user.
#
# Also available for other users if required.
# See https://mariadb.com/kb/en/unix_socket-authentication-plugin/

# this is only for embedded server
[embedded]

# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]

# This group is only read by MariaDB-10.0 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.0]

Results from Commands

$ netstat -nat |grep :3306
tcp6       0      0 :::3306                 :::*                    LISTEN
tcp6       0      0 127.0.0.1:54160         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:53974         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:42564         ESTABLISHED
tcp6       0      0 127.0.0.1:42566         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:49010         ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:39372         ESTABLISHED
tcp6       0      0 127.0.0.1:54104         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:42576         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:49178         127.0.0.1:3306          TIME_WAIT
tcp6       0      0 127.0.0.1:3306          127.0.0.1:39326         ESTABLISHED
tcp6       0      0 127.0.0.1:39266         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:53976         ESTABLISHED
tcp6       0      0 127.0.0.1:49142         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:49494         ESTABLISHED
tcp6       0      0 127.0.0.1:42590         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:54104         ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:39264         ESTABLISHED
tcp6       0      0 127.0.0.1:49434         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:49216         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:49010         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:39372         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:49142         ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:42590         ESTABLISHED
tcp6       0      0 127.0.0.1:54162         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:54106         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:49494         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:42576         ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:49434         ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:54160         ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:53974         ESTABLISHED
tcp6       0      0 127.0.0.1:39264         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:42566         ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:49216         ESTABLISHED
tcp6       0      0 127.0.0.1:39326         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:54162         ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:39266         ESTABLISHED
tcp6       0      0 127.0.0.1:42564         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:53976         127.0.0.1:3306          ESTABLISHED
tcp6       0      0 127.0.0.1:3306          127.0.0.1:54106         ESTABLISHED

Also

MariaDB [(none)]> SELECT User, Host FROM mysql.user WHERE Host <> 'localhost';
+--------+---------------+
| User   | Host          |
+--------+---------------+
| remote | [ Server A IP ] |
+--------+---------------+

and

ufw status | grep 3306
3306                       ALLOW       [ Server B IP ]

Server B trying to connect to Server A

$ mysql -u remote -h [ Server A IP ] -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '[ Server A IP ]' (111 "Connection refused")

also

ufw status | grep 3306
3306                       ALLOW       [ Server A IP ]

and

telnet 158.69.174.80 3306
Trying 158.69.174.80...
telnet: Unable to connect to remote host: Connection refused

You can see your issue here

MariaDB [(none)]> SELECT User, Host FROM mysql.user WHERE Host <> 'localhost';
+--------+---------------+
| User   | Host          |
+--------+---------------+
| remote | [ Server A IP ] |
+--------+---------------+

You really need [Server B IP] here

 GRANT ALL ON <DB>.* TO 'remote'@'server_B_IP';

This should do it.

ERROR 2003 (HY000): Can't connect to MySQL server on 'XXX.XX , ERROR 2003 (HY000): Can't connect to MySQL server on 'XXX.XX.XX.XX' (110). Posted October 28, 2017 124.6k views. UbuntuMySQLApacheFirewall. If you're using the no install zip, you need to execute mysqld.exe first to start the service, and then execute mysql.exe to open your connection.. The no install is nice, but if you intend to do any serious work with MySQL, you may want to consider either using the MSI to do a proper installation, or if you're doing web development work give XAMPP a try.

Set MYSQL bind-address to 0.0.0.0 because it usually only listens on 127.0.0.1 by default.

RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf

ERROR 2003 (HY000): Can't connect to MySQL , If you are using ubuntu , you have to use the following steps to avoid this error(if there is no replication enabled):. run the command vim  ERROR 2003 (HY000): Can't connect to MySQL server on 'x.x.x.x' (110) The client stuff should not have the mysql.sock file. Can anybody suggest me where to connect the sock file and mentioning sock file. I would very much appreiciate anyone help. Thanks in advance.

The issue was because the MySQL user {user}@{IP} had the {IP} as the IP of the MySQL-hoster server, not the IP of server which was connecting to the host; {IP} is used for the IP of the client which is connecting to the server.

ERROR 2003 (HY000): Can't connect to MySQL , Symptom: The error message: ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111) Appears white an attempt to  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

ERROR 2003 (HY000): Can't connect to MySQL , viggy@ubuntu:~$ mysql -u user.name -p -h xxx.xxx.xxx.xxx -P 3306 Enter password: ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.xxx​.xxx'  ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061) However, when I open the MySQL Administrator and choose Tools \ MySQL Command Line Client it opens \mysql\5.0\bin\mysql.exe and I'm at a mysql prompt and can do what I want in there.

ERROR 2003 (HY000): Can't connect to MySQL server , ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111). However, if I access mysql like so: mysql -u root -p. and then enter my password,​  ERROR 2003 (HY000): Can't connect to MySQL server on 'VM2_IP_Address' (110) Internal connexion on the VM2 is OK: (17:40:35) root@vm2-ovh:~# mysql -u replication_user

ERROR 2003 (HY000): Can't connect to MySQL server on localhost , The error (2003) Can't connect to MySQL server on ' server ' (10061) indicates that the network connection has been refused. You should check that there is a 

Comments
  • This didn't appear to fix anything (note there was no bind-address option in my.cnf in the first place). I manually added bind-address = 0.0.0.0 in /etc/mysql/my.cnf under [mysqld] and did service mysql restart, but it still does not work.