I’m attempting to connect to a MYSQL database remotely.
When trouble shooting I notice that the port is closed:
nmap -p 3306 34.34.34.34 (substituting for my server ip)
returns
PORT STATE SERVICE
3306/tcp closed mysql
In mysql config found at /etc/mysql/my.cnf I have
# Port or socket location where to connect
port = 3306
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
[mysqld]
sql_mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#bind-address = 0.0.0.0
local-infile=0
From with in server:
sudo ufw status
shows that 3306 is open:
3306 ALLOW Anywhere
3306 (v6) ALLOW Anywhere (v6)
In my EC2 security group I have 3306 open to ipv4 0.0.0.0/0
In plesk I have:
Allow remote connections from any host selected
Any idea why I can’t connect to the mysql database?
2
Answers
I solved this by changing the binding ip address in one of the include dir files:
These directories included multiple files and in one of them there was
I changed it to: #bind-address = 127.0.0.1
Instead of binding to locahost only, you can also bind to variable hosts like
bind-address = ::
Else only locahost can use the database. Sometimes that is desired for security reasons, but if you want to access the database from another IP, it needs this other setting, not limiting bind to locahost.