{"id":2317,"date":"2026-03-31T17:52:07","date_gmt":"2026-03-31T17:52:07","guid":{"rendered":"https:\/\/veerhost.com\/docs\/fix-cannot-connect-to-mysql-on-vps-access-denied-or-port-blocked\/"},"modified":"2026-03-31T17:54:49","modified_gmt":"2026-03-31T17:54:49","slug":"fix-cannot-connect-to-mysql-on-vps-access-denied-or-port-blocked","status":"publish","type":"docs","link":"https:\/\/veerhost.com\/de\/docs\/vps\/fix-cannot-connect-to-mysql-on-vps-access-denied-or-port-blocked\/","title":{"rendered":"Fix: Cannot Connect to MySQL on VPS (Access Denied or Port Blocked)"},"content":{"rendered":"<p class=\"wp-block-paragraph\">If you&#8217;re getting &#8220;Access denied for user&#8221; or can&#8217;t connect to MySQL remotely on your VPS, here&#8217;s how to diagnose and fix the most common causes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Cause 1: Wrong Username or Password<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Test your MySQL credentials locally on the VPS first:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u your_username -p<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enter the password when prompted. If you get &#8220;Access denied&#8221;, reset the password:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Log in as root\nmysql -u root -p\n\n# Reset a user's password\nALTER USER 'your_username'@'localhost' IDENTIFIED BY 'NewStrongPassword123!';\nFLUSH PRIVILEGES;\nEXIT;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Cause 2: MySQL Is Not Running<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Check if MySQL is running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl status mysql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If it&#8217;s stopped or failed, start it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl start mysql\nsystemctl enable mysql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If MySQL fails to start, check the error log:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>journalctl -u mysql -n 50 --no-pager<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Cause 3: Remote Connections Blocked (Port 3306)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">By default, MySQL only listens on <code>localhost<\/code> and port 3306 may be blocked by your firewall. To allow a specific IP to connect remotely:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Allow port 3306 in UFW:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Only allow your specific IP (recommended)\nufw allow from YOUR_IP to any port 3306\n\n# Or allow all (not recommended for production)\nufw allow 3306<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. Make MySQL listen on all interfaces<\/strong> \u2014 edit <code>\/etc\/mysql\/mysql.conf.d\/mysqld.cnf<\/code> and change:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bind-address = 127.0.0.1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bind-address = 0.0.0.0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then restart MySQL: <code>systemctl restart mysql<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. Grant remote access for the user:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p\n\nGRANT ALL PRIVILEGES ON your_database.* TO 'your_username'@'YOUR_IP' IDENTIFIED BY 'your_password';\nFLUSH PRIVILEGES;\nEXIT;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Cause 4: MySQL Crashed Due to Low Memory<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">On low-RAM VPS plans (512MB\u20131GB), MySQL can crash when memory runs out. Fix by adding a swap file. See: <a href=\"https:\/\/veerhost.com\/de\/docs\/how-to-set-up-a-swap-file-on-your-vps\/\">How to Set Up a Swap File on Your VPS<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Still Having Issues?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Contact Veerhost support at <a href=\"https:\/\/veerhost.com\/de\/support\/\">veerhost.com\/support<\/a> and include the exact error message and MySQL version (<code>mysql --version<\/code>).<\/p>","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re getting &#8220;Access denied for user&#8221; or can&#8217;t connect to MySQL remotely on your VPS, here&#8217;s how to diagnose and fix [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1967,"menu_order":11,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-2317","docs","type-docs","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/2317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/comments?post=2317"}],"version-history":[{"count":1,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/2317\/revisions"}],"predecessor-version":[{"id":2319,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/2317\/revisions\/2319"}],"up":[{"embeddable":true,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/1967"}],"wp:attachment":[{"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/media?parent=2317"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/doc_tag?post=2317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}