{"id":22612,"date":"2025-12-01T00:00:51","date_gmt":"2025-11-30T16:00:51","guid":{"rendered":"https:\/\/beyond-shenzhen.cn\/?post_type=blog&#038;p=22612"},"modified":"2026-04-16T11:15:36","modified_gmt":"2026-04-16T03:15:36","slug":"mysql-port-danger","status":"publish","type":"blog","link":"https:\/\/beyond-shenzhen.cn\/en\/blog\/mysql-port-danger\/","title":{"rendered":"\u3010Danger\u3011MySQL Port 3306 Open to External Access"},"content":{"rendered":"<p>We\u2019ll highlight the most dangerous configuration mistakes that web system and server administrators often make without realizing.<\/p>\n<p>\u201cBut the website is working fine, so it should be okay, right?\u201d<br \/>\n\u201cAnd there\u2019s a password, so it must be safe.\u201d<\/p>\n<p>Not at all. This kind of negligence can lead to serious security incidents.<\/p>\n<h2>What Happens If Port 3306 Is Exposed to the Internet?<\/h2>\n<p>Simply put, it\u2019s like leaving the doors of your website or system\u2019s database (MySQL or MariaDB) wide open to the world without any lock.<\/p>\n<p>These databases often contain sensitive internal information and customer data used by your systems.<\/p>\n<p>In other words, exposing such critical data online is basically saying: \u201cFeel free to take our data.\u201d<\/p>\n<p>Even if your website or system is password-protected, these passwords can still be easily cracked through brute-force attacks.<\/p>\n<table style=\"border-collapse: collapse; width: 100%; height: 72px;\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px; background-color: #2f8031;\" colspan=\"2\"><span style=\"color: #ffffff;\">Safe Configuration<\/span><\/td>\n<td style=\"width: 25%; height: 24px; background-color: #8f2828;\" colspan=\"2\"><span style=\"color: #ffffff;\">Dangerous Configuration<\/span><\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px; background-color: #c6f5c7;\">Web Server<\/td>\n<td style=\"width: 25%; height: 24px;\">3306 port bound to <span style=\"background-color: #f3f3f3;\">localhost<\/span> or <span style=\"background-color: #f3f3f3;\">127.0.0.1<\/span><\/td>\n<td style=\"width: 25%; height: 24px; background-color: #ffd6d6;\">Web Server<\/td>\n<td style=\"width: 25%; height: 24px;\">3306 port bound to <span style=\"background-color: #f3f3f3;\">0.0.0.0<\/span> or server\u2019s public IP<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 25%; height: 24px; background-color: #c6f5c7;\">External Access<\/td>\n<td style=\"width: 25%; height: 24px;\">Completely blocked from external connections<\/td>\n<td style=\"width: 25%; height: 24px; background-color: #ffd6d6;\">External Access<\/td>\n<td style=\"width: 25%; height: 24px;\">Open to external connections; anyone can access<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>* 127.0.0.1 is a special IP address reserved by the computer, representing \u201cthe local machine itself.\u201d<\/p>\n<h2>Why Does Such a Configuration Occur?<\/h2>\n<p>This dangerous setting arises not only from a lack of knowledge but also tends to happen under certain working conditions.<\/p>\n<p>The mindset of \u201cit\u2019s only temporary\u201d or \u201cit\u2019s working, so it\u2019s fine\u201d often lays the groundwork for serious, irreversible problems.<\/p>\n<p>The main causes can be categorized as follows.<\/p>\n<table style=\"border-collapse: collapse; width: 100%; height: 96px;\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 32.9146%; height: 24px; background-color: #ffd6d6;\">Initial setup mistakes<\/td>\n<td style=\"width: 67.0854%; height: 24px;\">Running the production system with default tutorial or example settings (e.g., bind-address = 0.0.0.0).<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 32.9146%; height: 24px; background-color: #ffd6d6;\">Temporary external service changes forgotten<\/td>\n<td style=\"width: 67.0854%; height: 24px;\">Database connections are temporarily opened to integrate with external analysis or backup tools and then forgotten.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 32.9146%; height: 24px; background-color: #ffd6d6;\">Handover omissions<\/td>\n<td style=\"width: 67.0854%; height: 24px;\">Settings changed by a predecessor as a \u201ctemporary fix\u201d were not documented and became permanent in production.<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 32.9146%; height: 24px; background-color: #ffd6d6;\">External vendor errors<\/td>\n<td style=\"width: 67.0854%; height: 24px;\">An outsourced system company accidentally applied test environment settings to production.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Risks of exposing port 3306<\/h2>\n<p>Exposing port 3306 to the Internet is not just a simple misconfiguration\u2014it poses a serious risk to business operations.<\/p>\n<p>The specific dangers can be explained from the following perspectives.<\/p>\n<h3>\u2460 Opens a Direct Attack Vector to the Database<\/h3>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #fff; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 16px; -webkit-overflow-scrolling: touch;\">\r\n<span style=\"line-height: 26px;\">-- Attackers can connect to your database directly and execute commands.\r\n<span style=\"color: #ffff00;\">DROP TABLE users;\r\nDELETE FROM orders;<\/span><\/span>\r\n<\/code><\/pre>\n<h3>\u2461 Risk of Data Leakage<\/h3>\n<p>\u3007 Customer data (names, email addresses, contact info)<br \/>\n\u3007 Passwords (still risky even if hashed)<br \/>\n\u3007 All order history and other sensitive\/confidential data<\/p>\n<h3>\u2462 Complete Site Destruction<\/h3>\n<p>If the database is deleted, the website will stop functioning (the site may no longer display).<\/p>\n<h3>\u2463 Server Takeover<\/h3>\n<p>Attackers can pivot from the database into the rest of the system, using your server as a launchpad for further attacks (e.g., ransomware).<\/p>\n<h2>Check Now Whether Port 3306 Is Exposed<\/h2>\n<p>You can use the online tools or commands below to verify whether MySQL port 3306 is publicly accessible.<\/p>\n<h3>\u2460 Check With Online Tools<\/h3>\n<p>Use port-checking websites to see if your server IP shows port 3306 as \u201cOPEN\u201d.<\/p>\n<p>\u3007 ping.eu<br \/>\n<a href=\"https:\/\/ping.eu\/port-chk\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/ping.eu\/port-chk<\/a><\/p>\n<p>\u3007 you get signal<br \/>\n<a href=\"https:\/\/www.yougetsignal.com\/tools\/open-ports\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/www.yougetsignal.com\/tools\/open-ports<\/a><\/p>\n<h3>\u2461 Check via Server Command Line<\/h3>\n<p>If the connection works from within the server, take immediate action.<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; background: #282c34; display: -webkit-box; font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 16px;\"><span style=\"color: #ffff00;\">telnet [server IP] 3306<\/span>\r\n<\/code><\/pre>\n<h2>Proper Configuration Guide for MySQL Port 3306<\/h2>\n<p>This guide explains the correct settings for MySQL port 3306, assuming that the web server and database run on the same host.<\/p>\n<p><span style=\"color: #ff0000;\">* Important: Before making any changes in a production environment, always back up your database. This ensures safety in case of configuration errors.<\/span><\/p>\n<h3>\u2460 Check the Current Configuration<\/h3>\n<p>Run the following command to view the current settings. If <span style=\"background-color: #f3f3f3;\">0.0.0.0<\/span> or your server\u2019s global IP appears, immediate action is required.<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #fff; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 16px; -webkit-overflow-scrolling: touch;\"># Check MySQL configuration file * Verify bind-address \r\n<span style=\"color: #d1edff;\">sudo grep -r \"bind-address\" \/etc\/mysql\/<\/span>\r\n\r\n# Check which network interface MySQL is currently listening on\r\n<span style=\"color: #d1edff;\">sudo netstat -tlnp | grep mysql<\/span>\r\n<\/code><\/pre>\n<blockquote><p>[mysqld]<br \/>\n<span style=\"color: #2f8031;\">bind-address = 127.0.0.1\u3000# This is safe\uff01<\/span><br \/>\n<span style=\"color: #8f2828;\"># bind-address = 0.0.0.0\u3000# If it looks like this, it\u2019s dangerous\uff01<\/span><\/p><\/blockquote>\n<h3>\u2461 Edit the MySQL Configuration File<\/h3>\n<p>Modify the MySQL configuration to allow connections only from localhost.<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #fff; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 16px; -webkit-overflow-scrolling: touch;\"># Edit the configuration file (path may vary by environment)\r\n<span style=\"color: #d1edff;\">sudo nano \/etc\/mysql\/mysql.conf.d\/mysqld.cnf<\/span>\r\n\r\n# Or\r\n<span style=\"color: #d1edff;\">sudo nano \/etc\/mysql\/my.cnf<\/span>\r\n<\/code><\/pre>\n<p>In the MySQL configuration file, locate and update the following lines.<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #fff; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 16px; -webkit-overflow-scrolling: touch;\"># Safe setting (confirm or modify to this)\r\n<span style=\"color: #c6f5c7;\">bind-address = 127.0.0.1\r\n\r\n<\/span>\r\n\r\n<span style=\"color: #ffd6d6;\"># Dangerous settings (must be changed if present)\r\n# bind-address = 0.0.0.0\r\n# bind-address = server's public IP <\/span>\r\n<\/code><\/pre>\n<h3>\u2462 Apply the Configuration Changes<\/h3>\n<p>After saving the MySQL configuration file, restart MySQL to apply the changes.<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #fff; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 16px; -webkit-overflow-scrolling: touch;\"># check configuration syntax\uff08Optional but recommended\uff09\r\n<span style=\"color: #d1edff;\">sudo mysqld --validate-config<\/span>\r\n\r\n# Restart MySQL service\r\n<span style=\"color: #d1edff;\">sudo systemctl restart mysql\r\n\r\n<\/span># Or (depending on your system)<span style=\"color: #d1edff;\">\r\nsudo service mysql restart\r\n<\/span>\r\n# Verify MySQL is running properly\r\n<span style=\"color: #d1edff;\">sudo systemctl status mysql<\/span>\r\n<\/code><\/pre>\n<h3>\u2463 Verify the Configuration<\/h3>\n<p>Check if the MySQL changes have been applied correctly.<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #fff; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 16px; -webkit-overflow-scrolling: touch;\"># Verify MySQL is responding on the new configuration\r\n<span style=\"color: #d1edff;\">sudo netstat -tlnp | grep mysql\r\n\r\n<\/span>\r\n\r\n<span style=\"color: #c6f5c7;\"># Expected output example\uff1a\r\n# tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -\r\n\r\n<span style=\"color: #ffffff;\"># Alternatively, check MySQL process info<\/span>\r\nsudo ps aux | grep mysql\r\n<\/span>\r\n<\/code><\/pre>\n<p>If you see <span style=\"background-color: #f3f3f3;\">127.0.0.1:3306<\/span>, the configuration is successful, and the database is now secure from external access.<\/p>\n<h3>Troubleshooting<\/h3>\n<p>If your website cannot connect to the database after modifying MySQL settings, follow these steps.<\/p>\n<ol>\n<li>Check the configuration file syntax \u2013 ensure there are no typos or extra characters.<\/li>\n<li>Verify your web application&#8217;s connection settings \u2013 make sure the host is set to localhost or 127.0.0.1.<\/li>\n<li>Check MySQL error logs \u2013 review the logs for detailed error messages.<\/li>\n<\/ol>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #fff; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 16px; -webkit-overflow-scrolling: touch;\"># View MySQL error log\r\nsudo tail -f \/var\/log\/mysql\/error.log \r\n<\/code><\/pre>\n<h2>Connecting to the Database From a Remote Environment<\/h2>\n<p>To connect to the database remotely, you must restrict access to a trusted fixed IP and use an SSH tunnel.<\/p>\n<p>Opening the SSH port without specifying a trusted IP introduces a serious security risk.<\/p>\n<h3>\u2460 Restrict Access to a Fixed IP on the Database Server<\/h3>\n<p>\u3007 RHEL \/ AlmaLinux (using firewalld)<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #fff; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 16px; -webkit-overflow-scrolling: touch;\"># Allow SSH connections only from a trusted fixed IP\r\n<span style=\"color: #d1edff;\">sudo firewall-cmd --permanent --add-rich-rule='rule family=\"ipv4\" source address=\"[YOUR_FIXED_IP]\" port port=\"22\" protocol=\"tcp\" accept'\r\nsudo firewall-cmd --permanent --remove-service=ssh\r\nsudo firewall-cmd --reload<\/span>\r\n\r\n# Verify the configuration\r\n<span style=\"color: #d1edff;\">sudo firewall-cmd --list-all\r\n<\/span><\/code><\/pre>\n<p>\u3007 Ubuntu (using UFW)<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #fff; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 16px; -webkit-overflow-scrolling: touch;\"># Allow SSH connections only from a trusted fixed IP\r\n<span style=\"color: #d1edff;\">sudo ufw allow from [YOUR_FIXED_IP] to any port 22<\/span>\r\n<span style=\"color: #d1edff;\">sudo ufw deny 22<\/span>\r\n<span style=\"color: #d1edff;\">sudo ufw reload#<\/span><\/code><\/pre>\n<h3>\u2461 Strengthen SSH Configuration<\/h3>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #fff; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 16px; -webkit-overflow-scrolling: touch;\"><span style=\"color: #d1edff;\">sudo nano \/etc\/ssh\/sshd_config<\/span><\/code><\/pre>\n<p>Add or modify the following settings.<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #fff; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 16px; -webkit-overflow-scrolling: touch;\"># Disable password authentication (key-based only)\r\n<span style=\"color: #d1edff;\">PasswordAuthentication no<\/span>\r\n\r\n# Restrict login to a specific user from a fixed IP\r\n<span style=\"color: #d1edff;\">AllowUsers username@[YOUR_FIXED_IP]<\/span>\r\n\r\n# Disable root login\r\n<span style=\"color: #d1edff;\">PermitRootLogin no<\/span><\/code><\/pre>\n<p>After saving the changes, restart the SSH service.<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #fff; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 16px; -webkit-overflow-scrolling: touch;\"><span style=\"color: #d1edff;\">sudo systemctl restart sshd<\/span><\/code><\/pre>\n<h3>\u2462 Establish an SSH Tunnel<\/h3>\n<p>After restricting access to a fixed IP, connect securely using an SSH tunnel.<\/p>\n<p>This ensures all traffic is encrypted through SSH, and MySQL port 3306 is never exposed to the public network.<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #fff; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 16px; -webkit-overflow-scrolling: touch;\"><span style=\"color: #d1edff;\">sh -L 3306:localhost:3306 [YOUR_USERNAME]@[SERVER_IP_OR_DOMAIN]<\/span><\/code><\/pre>\n<h2>Summary<\/h2>\n<p>Exposing your database directly to the Internet is like leaving an unlocked safe on the street.<\/p>\n<p>To avoid regrettable consequences, make sure to:<\/p>\n<p style=\"text-align: left;\">\u3007 Check that port 3306 is not publicly accessible<br \/>\n\u3007 Immediately fix the configuration if it is exposed<br \/>\n\u3007 Make regular security checks a routine<\/p>\n<h3>Related Services<\/h3>\n<table style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 50%; background-color: #138995;\"><span style=\"color: #ffffff;\">Website Development<\/span><\/td>\n<td style=\"width: 50%;\"><a href=\"https:\/\/beyond-shenzhen.cn\/en\/service\/website\" target=\"_blank\" rel=\"noopener\">https:\/\/beyond-shenzhen.cn\/en\/service\/website<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; background-color: #138995;\"><span style=\"color: #ffffff;\">Managed Cloud Services<\/span><\/td>\n<td style=\"width: 50%;\"><a href=\"https:\/\/beyond-shenzhen.cn\/en\/service\/server\" target=\"_blank\" rel=\"noopener\">https:\/\/beyond-shenzhen.cn\/en\/service\/server<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%; background-color: #138995;\"><span style=\"color: #ffffff;\">Cloud Business System<\/span><\/td>\n<td style=\"width: 50%;\"><a href=\"https:\/\/beyond-shenzhen.cn\/en\/service\/development\" target=\"_blank\" rel=\"noopener\">https:\/\/beyond-shenzhen.cn\/en\/service\/development<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><a class=\"border-circle-inline\" href=\"https:\/\/beyond-shenzhen.cn\/en\/contact\" target=\"_blank\" rel=\"noopener\">For Website Development and Managed Cloud Services<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We\u2019ll highlight the most dangerous configuration mistakes that web system and server administrators often make without realizing. \u201cBut the website is working fine, so it should be okay, right?\u201d \u201cAnd there\u2019s a password, so it must be safe.\u201d Not at all. This kind of negligence can lead to serious security incidents. What Happens If Port [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":22316,"template":"","meta":{"_acf_changed":false,"_locale":"en_US","_original_post":"https:\/\/beyond-shenzhen.cn\/?post_type=blog&p=22269"},"tags":[],"blogcat":[12],"class_list":["post-22612","blog","type-blog","status-publish","has-post-thumbnail","hentry","blogcat-it-web","en-US"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/beyond-shenzhen.cn\/wp-json\/wp\/v2\/blog\/22612","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/beyond-shenzhen.cn\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/beyond-shenzhen.cn\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/beyond-shenzhen.cn\/wp-json\/wp\/v2\/users\/3"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/beyond-shenzhen.cn\/wp-json\/wp\/v2\/media\/22316"}],"wp:attachment":[{"href":"https:\/\/beyond-shenzhen.cn\/wp-json\/wp\/v2\/media?parent=22612"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/beyond-shenzhen.cn\/wp-json\/wp\/v2\/tags?post=22612"},{"taxonomy":"blogcat","embeddable":true,"href":"https:\/\/beyond-shenzhen.cn\/wp-json\/wp\/v2\/blogcat?post=22612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}