Score:0

Undestanding how to connect remotely to a Mysql database

tt flag
Kay

Even if I found many old questions around this topic, I'm still unable to connect to a mysql database remotely. Beside my own specific issue I'd like to point out what are my doubts, in hope to serve whoever comes next, and it's a newbie like me.

Currently I have two Ubuntu machines. One that stores the db, the other that needs to connect to it remotely.

Here's what I did so far:

  • Changed bind address on mysqld.cnf file to 0.0.0.0, to make it listen to all IP addresses and restarted the server.
  • Ensured that the server is listening correctly via netstat -nat |grep :3306
  • Granted and flushed privileges to the root: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
  • Check the firewall via sudo ufw status
  • Tried to connect remotely using this terminal command: mysql -h 145.xxx.xxx.xxx -u root -p

This cause this error:

ERROR 2003 (HY000): Can't connect to MySQL server (111)

Is this procedure correct or I missed something? Is it correct to access from the other machine to the remote db with root user?

Romeo Ninov avatar
in flag
What about visibility between these machines? Can machine A "see" machine B (by IP:PORT)?
Kay avatar
tt flag
Kay
I tried `nmap -A myip -p 3306` and received this: `Note: Host seems down.`
HBruijn avatar
in flag
In addition to a host based-based firewall (ufw/iptables) on the MySQL server, that may be additional, external, firewalls between your client and the server; either actual firewalls or for example "security groups" in cloud environments. - My approach to debugging is described here: https://serverfault.com/a/1109720/37681
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.