Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › database security

How to Connect WordPress to a Remote Database Over a Private Network

By Freedom251 Team · · 12 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

WordPress can use a MySQL or MariaDB server on another machine when the database hostname resolves and its port is reachable from the WordPress host across a routable private network. The safe pattern is to create a dedicated database and account, allow the database port only from the web server’s private address, grant only normal data privileges, prove the connection with a database client, and then put the same values in wp-config.php.

A private route reduces internet exposure, but it does not replace database authentication, least-privilege grants, secret protection, or HTTPS for WordPress administration. The procedure below covers new installations and existing-site migrations.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What a remote WordPress database connection involves

A normal WordPress request crosses two services: the web server runs PHP and WordPress, while MySQL or MariaDB stores posts, users, settings, comments, and plugin data. With a remote database, PHP opens a TCP connection to the database server instead of a local socket. The connection succeeds only when every layer agrees:

  • Private DNS or a hosts entry resolves the database name to the intended private address.
  • The WordPress host has a route to that private subnet.
  • The database service listens on the private interface and port.
  • Security groups, network ACLs, and host firewalls allow traffic from the WordPress host.
  • The database account is allowed to connect from that source and has access to the selected database.
  • The constants in wp-config.php exactly match the tested values.

Testing those layers in that order prevents a WordPress error page from hiding a simpler DNS, routing, firewall, or grant problem.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Requirements and compatibility

Network and account prerequisites

  • A WordPress host and a MySQL or MariaDB host joined by a routable private network.
  • A unique database created for this WordPress installation.
  • A dedicated database account used by WordPress; do not reuse an administrator account.
  • A firewall or security-group rule that permits the database port only from the WordPress host’s private IP address or the smallest required subnet.
  • Administrative access to the database server and to the WordPress host so you can test both sides.

Supported software baseline

The current WordPress requirements guidance recommends PHP 8.3 or newer, MySQL 8.0 or newer, MariaDB 10.11 or newer, and HTTPS. The WordPress Hosting Handbook also lists MySQL 8.4 LTS and MariaDB 11.8 LTS among newer long-term-support branches. Check the live requirements and vendor support policies before deployment because end-of-life dates change. Older combinations may still start, but running an unsupported database or PHP release increases security and maintenance risk.

Choose the private connectivity model

Your provider or data-center topology determines how the two hosts communicate. Select the narrowest design that both sides support.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Option Exposure Operational trade-offs Best fit
Private subnet or VPC Database traffic stays on the provider’s private fabric; no public listener is required. Usually the lowest latency and simplest firewall model. Both servers must share a compatible network, and failure of that network affects the application. Web and database servers in the same cloud, region, or data center.
Site-to-site VPN Traffic is encrypted between otherwise separate networks and the database can remain private. Requires tunnel endpoints, route exchange, key management, monitoring, and a second failure domain. MTU and tunnel outages need explicit alerting. Separate cloud networks, offices, or an on-premises database that cannot join the web provider’s private subnet.
Private endpoint or provider peering Uses a provider-supported private service path rather than a public database address. Availability, routing rules, regions, and failover behavior depend on the database provider. Document how a standby endpoint is exposed. Managed database services that offer private connectivity.
Public endpoint with an IP allow-list The endpoint remains internet-reachable even when only one source address is allowed. Fastest to deploy, but it is the weakest match for a private-network requirement. Public DNS, scanning, provider controls, and changing egress IPs add risk. Only when private connectivity is unavailable and compensating controls, TLS, narrow allow-lists, and monitoring are formally accepted.

Keep the web and database in the same private region or data center when practical. Every request still pays for network distance, routing, connection setup, query volume, and database load; there is no universal latency limit that guarantees a good WordPress experience.

Step-by-step connection procedure

1. Record private addresses, names, and ports

Write down the WordPress host’s private IP, the database host’s private IP, the private DNS name, and the database listener port. MySQL commonly uses port 3306, but your service may use another port. Decide whether DNS will provide a stable name such as db.internal.example or whether a private address will be used temporarily. A DNS name is easier to change during a database move or failover.

Do not use a public address in DB_HOST when the design is intended to be private. If the two machines are in different networks, establish the VPN, peering, or private endpoint and confirm that routes exist in both directions before continuing.

2. Create a database and a dedicated account

On the database server, create a unique schema and an account whose allowed source is the WordPress host’s private address. The exact host syntax varies by MySQL or MariaDB version; the important control is that the account is not accepted from every host.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
CREATE DATABASE wordpress_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wordpress_app'@'10.20.30.15' IDENTIFIED BY 'replace-with-a-long-unique-secret';
GRANT SELECT, INSERT, UPDATE, DELETE ON wordpress_db.* TO 'wordpress_app'@'10.20.30.15';
FLUSH PRIVILEGES;

Replace the example address, names, and secret. The WordPress Hosting Handbook states that normal operations such as publishing, media uploads, comments, user creation, and plugin installation need data read and write privileges: SELECT, INSERT, UPDATE, and DELETE. Do not give this application account global administration, FILE, GRANT OPTION, or access to unrelated databases. If a migration tool temporarily needs extra privileges, use a separate short-lived administrator account and remove it after the import.

Verify the grant before leaving the database host:

SHOW GRANTS FOR 'wordpress_app'@'10.20.30.15';

3. Bind the database service to the private interface

Configure MySQL or MariaDB to listen on the private interface required by your topology. A service bound only to 127.0.0.1 cannot accept a remote WordPress connection; a service bound to every interface may expose an unintended public path. The configuration file and directive name differ by distribution, so use the database vendor’s documentation for your installation, then restart or reload the service according to its supported procedure.

Confirm the listener locally on the database host and make sure the process is not listening on a public interface unless that is deliberately required. If a managed service controls the listener, use its private-endpoint setting instead of editing a server file.

4. Restrict the network firewall

Create an inbound rule for the database port from only the WordPress host’s private IP, or from the smallest private subnet that genuinely contains the web tier. Apply the rule at every relevant layer: cloud security group, network ACL, operating-system firewall, and any VPN or router policy. Remove broad temporary rules such as an entire internet address range after testing.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Private reachability is an access-control layer, not authentication. Keep the dedicated account, password, and grants even when the database packets never traverse the public internet.

5. Prove DNS, routing, the port, and credentials from the WordPress host

Run these checks on the machine that runs PHP, not from your laptop. They test progressively deeper layers.

Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
  1. Resolve the private name.
    getent hosts db.internal.example

    Confirm that the returned address is the intended private address, not a public record.

  2. Check the route.
    ip route get 10.20.0.10

    Use the actual database private address and verify that the route exits through the expected private interface or tunnel.

  3. Test the TCP port.
    nc -vz -w 3 db.internal.example 3306

    A successful TCP result proves reachability to the listener, not that the account is valid.

  4. Authenticate with the same values WordPress will use.
    mysql --protocol=tcp -h db.internal.example -P 3306 -u wordpress_app -p wordpress_db -e 'SELECT 1;'

    Enter the password at the prompt so it is not exposed in shell history or process listings. A successful SELECT 1 proves name resolution, routing, firewall, listener, account, password, and database selection together.

If this client test fails, fix the underlying layer before changing WordPress. A WordPress configuration edit cannot repair a missing route or a rejected grant.

6. Set the WordPress connection constants

Back up wp-config.php, then set the four database constants to the values you just tested. Keep the file outside public download paths and preserve its PHP syntax.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
define( 'DB_NAME', 'wordpress_db' );
define( 'DB_USER', 'wordpress_app' );
define( 'DB_PASSWORD', 'replace-with-a-long-unique-secret' );
define( 'DB_HOST', 'db.internal.example' );

Use the private DNS name in DB_HOST. If the server uses a non-default port, append the port using the host-and-port syntax documented for your WordPress and database environment, for example db.internal.example:3307. Do not append a port when the normal port is already in use unless your host requires it. Keep the database password free of accidental whitespace and make sure the PHP file contains matching quotation marks and semicolons.

WordPress’s configuration example uses these same four constants. If your installation uses a nonstandard table prefix, retain the existing $table_prefix value; changing it makes WordPress look for a different set of tables.

7. Install a new site or migrate an existing one

For a new site, open the WordPress URL after saving the file and complete the installer. The installer should create tables in the remote schema using the account’s granted privileges.

For an existing site, import the database into the remote schema before switching traffic. A typical sequence is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
  1. Put the old site in maintenance mode or stop writes so the final export is consistent.
  2. Export the complete WordPress database, including all tables and their current prefix.
  3. Import the export into wordpress_db on the remote server using an administrative migration account, not the restricted runtime account.
  4. Copy the wp-content/uploads directory and any other required file-based assets to the new web host.
  5. Check the imported siteurl, home, table prefix, active plugins, and filesystem paths against the new deployment.
  6. Update wp-config.php, run the client test again, and load the site while monitoring logs.

When a domain changes, use a WordPress-aware search-and-replace process that understands serialized data. A blind SQL text replacement can corrupt serialized plugin settings. Keep the old site available until logins, publishing, media uploads, scheduled tasks, and plugin features have been verified.

8. Protect administration with HTTPS

A private database path does not encrypt a visitor’s browser connection to WordPress. Serve the site and especially login and administration traffic over HTTPS. WordPress supports FORCE_SSL_ADMIN in wp-config.php:

define( 'FORCE_SSL_ADMIN', true );

Enable it only after the web server or reverse proxy correctly terminates TLS and WordPress receives the forwarded HTTPS state. If the proxy fails to pass that state, administrators can be caught in redirect loops or receive mixed HTTP/HTTPS behavior. Follow the proxy’s WordPress HTTPS guidance, test an administrator login in a private browser window, and then enforce the setting.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How to validate the finished deployment

After the site loads, test the operations that exercise different database writes and file paths:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Sign in and open the dashboard over HTTPS.
  • Create, edit, and publish a draft post.
  • Upload an image and confirm that the file appears in the expected uploads directory and its attachment record is saved.
  • Submit a comment if comments are enabled and moderate it.
  • Create a test user or update a profile, then remove the test account.
  • Run a plugin update in a maintenance window and confirm that the database account is not being asked for administrative privileges.
  • Restart the web process and, separately, the database service during a planned test to observe error handling and recovery.

Watch web-server and PHP logs for connection failures, database error logs for rejected sources, and host metrics for CPU, memory, connections, disk space, and network drops. Record the private DNS name, port, firewall rule, account owner, backup location, and rollback procedure in your operations documentation.

Troubleshoot in dependency order

The private name does not resolve

Run getent hosts or your platform’s DNS query from the WordPress host. Check that the private DNS zone is associated with the web host’s network, that split-horizon DNS is returning the private record, and that the name in DB_HOST has no typo. If DNS is intentionally unavailable, test with the private IP temporarily; do not leave an unstable public address in production.

The port times out or is refused

A timeout normally indicates a missing route, security-group rule, ACL, or firewall permission. A refusal usually means the host is reachable but no service is listening on that address and port, or the service is bound only to localhost. Check the route, listener address, database service state, and every firewall layer. Confirm that the rule’s source is the web server’s private IP, not the administrator’s workstation address.

The client reports access denied

Repeat the client command with exactly the host, port, username, password, and database from wp-config.php. Inspect SHOW GRANTS and the account’s allowed host. MySQL accounts distinguish both username and source host, so an account created for 10.20.30.15 will not necessarily accept a connection arriving from another private address after a web-tier change. Reset the secret through an administrative channel rather than placing it in a ticket or log.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The database is unknown or tables are missing

An unknown-database error means DB_NAME does not match the schema name or the account cannot see it. If WordPress opens an installer on a site that should already exist, check the imported tables and $table_prefix before proceeding; installing again can create a second, empty set of tables.

HTTPS redirects loop after enabling administration enforcement

Check TLS termination and the reverse proxy’s forwarded-protocol header. WordPress must be told that the original browser request was HTTPS. Temporarily disable the enforcement constant through a controlled configuration change, correct the proxy mapping, test an admin login, and then re-enable it.

The site is slow although the connection works

Measure from the WordPress host rather than guessing. Review database connection time, slow-query logs, query volume, CPU and memory pressure, and network retransmissions. Keep both services geographically close, reduce unnecessary plugin queries, and size the database for its workload. A successful port test says nothing about query latency or saturation.

Security controls that should remain in place

  • Least privilege: Keep the runtime account limited to the WordPress schema and normal data privileges. Separate migration, backup, and administrative accounts.
  • Narrow network rules: Allow the database port only from the web host’s private address or an explicitly required private subnet. Remove temporary broad rules.
  • Secret handling: Make wp-config.php readable only by the service account and administrators, use a long unique password, rotate it through a planned change, and never paste it into public logs or support tickets.
  • Encrypted administration: Require HTTPS for login and dashboard traffic even when database packets stay private.
  • Backups and recovery: Keep tested database backups and a copy of the WordPress files, document restore credentials, and periodically perform a restore into an isolated environment.
  • Patch management: Track supported PHP, MySQL or MariaDB, WordPress core, themes, and plugins. Apply security updates in a maintenance process that includes a rollback plan.
  • Monitoring: Alert on repeated authentication failures, unexpected source addresses, connection exhaustion, slow queries, disk pressure, and tunnel or private-network outages.

Performance, failover, and operational trade-offs

Moving the database off the web host can improve storage isolation, scaling, backups, and administrative separation, but it adds a network hop and a new failure domain. Every PHP request that queries WordPress depends on DNS, the private route, the database listener, and available database connections. A VPN adds tunnel health and route convergence to that chain; a provider private endpoint may add its own regional failover behavior.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Measure the deployment you actually run. Capture connection errors and query timings under normal traffic and during backups, failovers, and plugin updates. There is no official universal latency threshold for WordPress remote databases. If measurements show unacceptable delay, first co-locate the services, verify that DNS is not repeatedly failing over, inspect slow queries, and check database resource limits before adding architectural complexity.

Design failover deliberately: use a stable private name that can be repointed, document how firewall rules follow a standby address, and test what WordPress does while the primary database is unavailable. Do not assume that a private endpoint, VPN, or database replica automatically provides transparent write failover.

Common mistakes to avoid

  • Putting a public database address in DB_HOST when the requirement is private connectivity.
  • Opening port 3306 to the entire internet or to a broad cloud range “temporarily” and forgetting to remove it.
  • Granting the WordPress account global or administrative privileges because a migration account needed them.
  • Testing from a laptop instead of from the actual WordPress host.
  • Changing DB_HOST before proving the same host, port, and credentials with the MySQL client.
  • Using a database name or table prefix that differs from the imported site.
  • Enabling FORCE_SSL_ADMIN before the reverse proxy forwards HTTPS correctly.
  • Copying a database password into shell history, chat, tickets, or diagnostic output.
  • Assuming a successful TCP handshake proves that queries will be fast or that the database has enough capacity.

When each layer is verified independently, the final WordPress change is small: point DB_HOST at the private database name, supply the dedicated credentials, and let WordPress use the least privilege it needs.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

database securityMariaDBMySQLprivate networkWordPresswp-config.php

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.