DEV Community

SWAPNIL AHMMED SHISHIR
SWAPNIL AHMMED SHISHIR

Posted on

MySQL remote access problem in the hosting provider

βœ… STEP-BY-STEP FIX (Hosting Provider Side)


πŸ” 1. Open Port 3306 in the Firewall

If using firewalld (CentOS/RHEL):

sudo firewall-cmd --permanent --add-port=3306/tcp
sudo firewall-cmd --reload
Enter fullscreen mode Exit fullscreen mode

If using ufw (Ubuntu/Debian):

sudo ufw allow 3306/tcp
sudo ufw reload
Enter fullscreen mode Exit fullscreen mode

🧠 This opens port 3306 so external IPs can reach it.


βš™οΈ 2. Configure MySQL to Accept Remote Connections

Open my.cnf or mysqld.cnf:

sudo nano /etc/my.cnf         # Common on CentOS
# or
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf  # Common on Ubuntu
Enter fullscreen mode Exit fullscreen mode

Find this line:

bind-address = 127.0.0.1
Enter fullscreen mode Exit fullscreen mode

Change to:

bind-address = 0.0.0.0
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ This makes MySQL accept connections from all IPs, not just localhost.

Then restart MySQL:

# CentOS/RHEL
sudo systemctl restart mysqld

# Ubuntu/Debian
sudo systemctl restart mysql
Enter fullscreen mode Exit fullscreen mode

πŸ§‘β€πŸ’» 3. Make Sure the MySQL User Has Remote Access

In MySQL shell:

GRANT ALL PRIVILEGES ON tsgbsite_tsgb_db.* TO 'tsgbsite_tsgb_us'@'%' IDENTIFIED BY 'YAqmBg9UPB^T';
FLUSH PRIVILEGES;
Enter fullscreen mode Exit fullscreen mode

πŸ› οΈ This allows the user to connect from any host.


πŸ§ͺ 4. Test It Yourself

From your Node.js app or terminal:

mysql -h 103.163.246.85 -u tsgbsite_tsgb_us -p
# Enter password when prompted
Enter fullscreen mode Exit fullscreen mode

If the connection succeeds, you're all set!


πŸ“ Summary You Can Send to Hosting Support

πŸ”§ Ask your hosting provider to do these:

  1. Open port 3306 in the firewall (for incoming TCP).
  2. Set MySQL bind-address to 0.0.0.0 (not 127.0.0.1).
  3. Restart MySQL service after the change.
  4. Ensure MySQL user has privileges from % (any host).

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.