MySQL on a Windows VPS: Secure Remote Access Setup

Install MySQL Server as a Windows service, then allow remote clients safely with an IP-scoped user, required TLS and a firewall rule for one address.

dns WindowsVPS Team calendar_today schedule5 min read
MySQL on a Windows VPS: Secure Remote Access Setup
tocOn this page 9 sections
  1. Install MySQL Server as a Windows service
  2. Keep root local
  3. Create a remote user tied to one IP
  4. Set the bind address and require TLS
  5. Open 3306 for one address only
  6. Test from the client
  7. Safer option: an SSH tunnel with 3306 closed
  8. Back up before you rely on it
  9. FAQ

To run MySQL on a Windows VPS and reach it from another machine, install MySQL Server as a Windows service. Then create a database user that can only connect from your client's IP address, require TLS, and open TCP 3306 in Windows Defender Firewall for that one address. If you can, skip the open port completely and connect through an SSH tunnel.

Install MySQL Server as a Windows service

Over RDP, download the MySQL Community Server MSI for Windows from dev.mysql.com and run it. The setup and configuration screens change between releases, but the choices that matter are the same:

  • Config type: Server Computer, or Dedicated Computer if MySQL is the main workload on the VPS.
  • Connectivity: TCP/IP on port 3306. Leave the X Protocol port (33060) off unless your app needs it.
  • Authentication: the default strong password method. Set a long root password and store it in your password manager.
  • Windows Service: start at system startup and run as the Standard System Account.
  • Firewall: if the wizard offers to open Windows Firewall ports for network access, clear that box. You will create a narrower rule later.

When it finishes, check the service and listener from an elevated PowerShell window:

Get-Service MySQL*
Get-NetTCPConnection -LocalPort 3306 -State Listen

Add the client tools to your path for the session. Replace X.Y with your installed version folder:

$env:Path += ';C:\Program Files\MySQL\MySQL Server X.Y\bin'
mysql -u root -p

Keep root local

Before you expose anything, check which accounts exist:

SELECT user, host FROM mysql.user;

Root should only appear as 'root'@'localhost'. If you see a root entry with host %, or an account with an empty user name, drop it with DROP USER. Never use root for remote access.

Create a remote user tied to one IP

MySQL matches every login on both user name and source host. Use that to limit each account to the address it really connects from. In this example 203.0.113.10 is your office or app server:

CREATE DATABASE appdb;
CREATE USER 'appuser'@'203.0.113.10'
  IDENTIFIED BY 'use-a-long-random-password'
  REQUIRE SSL;
GRANT SELECT, INSERT, UPDATE, DELETE ON appdb.* TO 'appuser'@'203.0.113.10';

Give out only the privileges the application uses. Schema changes can run from a separate admin account that only connects locally or through a tunnel.

Set the bind address and require TLS

The server config is in C:\ProgramData\MySQL\MySQL Server X.Y\my.ini. ProgramData is hidden, so type the path into File Explorer. Open the file in Notepad run as administrator, and under [mysqld] set:

bind-address=0.0.0.0
require_secure_transport=ON

require_secure_transport rejects any TCP connection that isn't encrypted, whatever the client asks for. On its first start, current MySQL versions create a self-signed CA and server certificate (ca.pem and server-cert.pem) in the data directory, so TLS works without extra setup. Restart the service and confirm:

Restart-Service MySQL*
mysql -u root -p -h 127.0.0.1 -e "\s"

The status output should show an SSL cipher in use.

Open 3306 for one address only

First look for any broad MySQL rule the installer may have created:

Get-NetFirewallPortFilter | Where-Object LocalPort -eq 3306 |
  Get-NetFirewallRule | Select-Object DisplayName, Enabled, Profile

Remove or disable anything that allows all addresses. Then add a scoped rule:

New-NetFirewallRule -DisplayName 'MySQL 3306 - office' `
  -Direction Inbound -Protocol TCP -LocalPort 3306 `
  -RemoteAddress 203.0.113.10 -Action Allow

If you have more than one client, list the addresses comma-separated in -RemoteAddress and create a matching MySQL user for each one. If your home IP changes often, don't widen the rule. Use the tunnel method below. For the rest of the server's lockdown, work through our Windows Server VPS hardening checklist.

Test from the client

Test-NetConnection your-vps-ip -Port 3306
mysql -h your-vps-ip -u appuser -p --ssl-mode=REQUIRED

To protect against a spoofed server, copy ca.pem from the server's data directory to the client and use --ssl-mode=VERIFY_CA --ssl-ca=ca.pem. Application connection strings have matching SSL options.

Safer option: an SSH tunnel with 3306 closed

Windows Server includes OpenSSH Server as an optional feature. With a tunnel, MySQL only listens on loopback and the internet never sees port 3306:

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Set-Service sshd -StartupType Automatic
Start-Service sshd

Set bind-address=127.0.0.1 in my.ini, restart MySQL, and create the user as 'appuser'@'127.0.0.1'. On the client, run:

ssh -L 3307:127.0.0.1:3306 youradmin@your-vps-ip

Then point your tool at 127.0.0.1 port 3307. Scope the firewall rule for port 22 to your addresses as well, and use key-based logins. This setup works well for remote dev work. See our Windows VPS for development and testing guide for more on that use. If MySQL backs a site running on the same box, keep it on loopback and skip remote access entirely; our IIS and ASP.NET hosting guide covers that setup.

Back up before you rely on it

Schedule a nightly mysqldump --single-transaction --routines appdb with Task Scheduler, and copy the dump files off the VPS. Rclone on Windows Server handles the off-site copy.

FAQ

Why do I get "Host is not allowed to connect to this MySQL server"?

That is error 1130. The packets reached MySQL, but no account matches your user name and source IP. Run SELECT user, host FROM mysql.user; and check that the host matches the public IP the server actually sees, which is often a NAT address and not your local one.

The connection just times out. What should I check?

A timeout usually means the firewall is dropping the traffic before it reaches MySQL. Confirm the rule's RemoteAddress matches your current IP, check that the service is listening with Get-NetTCPConnection -LocalPort 3306, and make sure bind-address isn't still 127.0.0.1.

Can I just use '%' as the host?

Only if the firewall already limits who can reach port 3306, and even then a specific IP is safer. With '%' and an open port, anyone on the internet can try to brute-force the password.

Run this on your own Windows VPS

Get a Windows VPS from WindowsVPS in about 60 seconds, with full Administrator access over RDP, NVMe storage and the Windows license included.

Buy a Windows VPS →

dns

Written by the WindowsVPS Team

We run Windows Server VPS hosting and write these guides from the same setups our customers use: RDP, PowerShell, trading terminals and always-on bots. Questions about a guide? Contact us.

About WindowsVPS Windows VPS guides All articles

Ready to deploy your server?

Windows or Linux VPS — up and running in under 60 seconds.