AWS Billing Support How to fix AWS Lightsail WordPress database connection error on startup
If your WordPress site shows “Error establishing a database connection” right after Lightsail deployment (or after an update/reboot), you’re likely dealing with one of a few operational issues: wrong DB credentials, the wrong database endpoint/port, a stale WordPress config, a partially-migrated database, or (more rarely) a Lightsail/LAMP stack change that broke the service.
Because you mentioned “on startup,” I’ll assume the error appears immediately after provisioning or after you restart the instance. I’ll also cover the parts that usually cause delays for real users: Lightsail database add-ons, credentials rotation, firewall/security group mismatches, and the account/billing checks that can silently block DB connectivity when resources are paused or replaced.
First triage: confirm what is failing (WordPress vs database service)
Before you change anything, do a quick, decisive check. In my experience, users burn hours changing wp-config.php without confirming whether MySQL is actually up.
1) Check WordPress error details
- Open the site in a private window and disable caching plugins temporarily if you have them.
- If you can access the server via SSH, check the WordPress error logs:
/var/www/html/wp-content/debug.log(if debug logging is enabled)- Or enable debug temporarily via
wp-config.php(see below)
2) SSH into the Lightsail instance and check whether the database service is running
Depending on how you deployed WordPress, your database might be:
- On the same instance (MySQL/MariaDB service locally), or
- A separate Lightsail database endpoint (managed database add-on)
Run these commands:
# Check MySQL/MariaDB service status (local DB case)
sudo systemctl status mysql
# or
sudo systemctl status mariadb
# Check port listening
sudo ss -lntp | grep -E ':(3306|33060)\b'
Interpretation:
- If MySQL isn’t running locally, WordPress will fail regardless of credentials—focus on service startup and logs.
- If MySQL isn’t applicable because you use a Lightsail managed database, then check network/connectivity to the DB endpoint.
Most common cause: wrong DB credentials or stale connection info in wp-config.php
When the error starts “on startup,” the #1 practical reason I see is that someone replaced or recreated the Lightsail database, but WordPress still points to the old endpoint/user/password.
Where to look
On the instance:
sudo nano /opt/bitnami/wordpress/wp-config.php
# or
sudo nano /var/www/html/wp-config.php
Search for these lines:
define('DB_NAME', '...');
define('DB_USER', '...');
define('DB_PASSWORD', '...');
define('DB_HOST', '...');
Check DB_HOST format (managed DB endpoint)
For Lightsail managed databases, DB_HOST is typically the database endpoint (or host + port depending on your deployment).
Common mistakes:
- Using
localhostwhile the DB is managed remotely - Using the instance IP instead of the DB endpoint
- AWS Billing Support Using an old endpoint after DB recreation
Quick verification by testing credentials from the server
Install a MySQL client if needed (some images already have it):
mysql --version || sudo apt-get update && sudo apt-get install -y mysql-client
Then try:
mysql -h <DB_HOST> -u <DB_USER> -p -e "SELECT NOW();"
If this fails, WordPress will fail too—now you know you’re debugging connectivity/credentials, not WordPress itself.
If you use a Lightsail database add-on: fix connectivity and port access
When WordPress can’t connect, you’re often blocked at the network layer—especially if you moved instances, changed firewall rules, or created the DB add-on in a different setup.
Confirm you’re using the right Lightsail database endpoint
- In Lightsail console → your database resource → copy the endpoint
- Update
DB_HOSTinwp-config.phpaccordingly
Check firewall rules / ports
A lot of “startup errors” are actually allowed ports drift: users harden security and then restart.
In Lightsail, for the instance network access settings:
- Ensure inbound rules don’t block outbound (usually outbound is not blocked, but confirm)
- Ensure the database allows the instance’s connection (Lightsail managed DB typically requires using the proper endpoint and network config; rules may be limited compared to raw EC2 security groups)
AWS Billing Support On the server, confirm port reachability:
# Replace DB_HOST
nc -vz <DB_HOST> 3306
AWS Billing Support Results:
- succeeded → focus back on credentials/DB existence
- timed out/refused → fix networking/firewall/routing and ensure the DB endpoint is correct
Database service running? If local: restart MySQL/MariaDB safely
If your WordPress deployment uses a local database (common with some One-Click templates), you should verify the DB daemon immediately.
AWS Billing Support Start/enable the service
sudo systemctl start mysql
sudo systemctl enable mysql
If you use MariaDB instead:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Read MySQL logs to pinpoint the startup failure
/var/log/mysql/error.log/var/log/mysqld.log(varies by distro)
Common log themes:
- Disk full (systemd fails to start; WordPress errors follow)
- Corrupted tables after abrupt power loss
- Unauthorized config changes after an update
To check disk pressure:
df -h
sudo du -sh /var/lib/mysql
DB exists, but WordPress can’t see it: user privileges and wrong DB_NAME
Another frequent case: the DB server is reachable, but the DB_USER doesn’t have access to DB_NAME (especially after restoring/migrating or recreating the database).
AWS Billing Support Validate from MySQL client
mysql -h <DB_HOST> -u <DB_USER> -p
# Then inside:
SHOW DATABASES;
USE <DB_NAME>;
SHOW TABLES;
If USE <DB_NAME> fails with “Access denied,” you need to update the WordPress credentials or re-grant privileges.
Grant privileges (only if you have admin access)
# Run as a MySQL admin/root, not as DB_USER
GRANT ALL PRIVILEGES ON <DB_NAME>.* TO '<DB_USER>'@'%';
FLUSH PRIVILEGES;
Note: In managed DB scenarios, admin access may be restricted—so the practical path is often to use the database user created by Lightsail (or rotate credentials through the Lightsail database resource settings).
WordPress fix that unblocks quickly: enable debug and reset the broken config values
If you need a fast diagnosis without guessing, enable WordPress debug (temporary) to surface the specific DB error.
Temporary debug toggle
sudo nano <path-to-wp-config.php>
# Set:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
Then reload the site and check the debug log. You’ll usually see whether the failure is “Access denied,” “Unknown database,” or “Can’t connect to MySQL server.”
This matters because each error points to a different operational fix:
- Unknown database →
DB_NAMEmismatch or database not created - Access denied → credentials/user privileges mismatch
- Can’t connect → endpoint, port, routing, or DB service down
If you recently recreated the Lightsail database: confirm whether credentials changed
Real operational friction: users create a new DB add-on to recover from corruption, but they forget to update the WordPress config.
What to do:
- In Lightsail → open the database resource
- Copy the database name, master/DB user, and password (or connection string)
- Update
wp-config.phpaccordingly
Then test with the MySQL client command from earlier.
Account/billing-related causes: Lightsail resource changes can look like “DB broke”
This section is for the scenario you might not think about: sometimes the database isn’t “down” technically—the account state or payments caused resources to pause, be replaced, or fail provisioning/renewal.
What to check in your AWS account (practical)
- Billing & account status: verify no payment method failures
- Lightsail instance and database status: confirm they’re in “running” / “available” states
- Snapshots/restores: if you restored, your DB user/password may have been regenerated depending on how the restore was performed
Risk control / compliance gating that can interrupt operations
A minority of users hit an AWS account risk-control review that doesn’t immediately block every action, but can restrict certain operations or delay changes. When this happens around the time you deployed or restarted, the service might be in a partially provisioned state.
If you see unusual limitations or the Lightsail database isn’t in the expected state after a change, check whether AWS sent any notices about verification steps or account limits.
Practical action:
- Confirm your account has completed any identity verification steps required by AWS (especially if you recently created the account or changed billing profile).
- Make sure the payment method is valid and matches the account profile to reduce payment retries that can trigger risk scoring.
Cost comparisons and decision points: database add-on vs local DB in Lightsail (and how it affects this error)
AWS Billing Support When you fix connection errors repeatedly, it’s reasonable to ask: “Should I change architecture?” Below is a decision-oriented comparison focused on what affects connection stability and startup behavior.
| Option | Common failure when WordPress won’t start | Operational overhead | Typical cost shape |
|---|---|---|---|
| Lightsail instance with local MySQL | MySQL service down after reboot; local disk full; config drift | High: you manage DB lifecycle, upgrades, and troubleshooting | Mostly instance-based (compute + storage) |
| Lightsail managed database add-on | Wrong DB endpoint/user/password; networking/port access; DB paused/unavailable | Medium: update wp-config.php when credentials/endpoint changes |
Separate database charges; often predictable monthly |
Rule of thumb from my field work: if you keep seeing this error “after a restart,” local DB is usually the culprit. If it happens after DB recreation, migrations, or template redeploys, managed DB credential/endpoint mismatch is usually the culprit.
Frequently asked questions (the questions users actually search)
1) “I changed passwords—why didn’t it work after reboot?”
WordPress stores DB credentials in wp-config.php. If the database password was rotated (or you recreated the DB), reboot won’t help—WordPress still uses old credentials. Update DB_USER/DB_PASSWORD and retest with the MySQL client.
2) “What if DB_HOST is localhost?”
With a managed Lightsail database, localhost points to the web instance itself, not the database. Use the database endpoint provided by Lightsail.
3) “I can connect with MySQL client, but WordPress still fails.”
That usually means WordPress is reading a different config file than you edited, or you have multiple WordPress installations. Confirm the correct docroot and verify the actual file path used by your web server.
For example, check where the web server points:
sudo apachectl -S
# or for Nginx:
sudo nginx -T | grep -R "root " -n
4) “My WordPress works on one instance but fails on another.”
Credentials/endpoint mismatch and missing DB privileges are the usual culprits. Also verify the database is accessible from the new instance network path.
5) “How do I avoid this during updates?”
Before updates or redeployments:
- Back up
wp-config.phpand record the current values ofDB_HOST,DB_USER,DB_NAME - After any DB recreation, immediately update
wp-config.phpbefore restarting WordPress - If you use plugins for caching or “one-click migrations,” disable them temporarily to reduce noise during troubleshooting
Common reasons for registration/verification/payment issues that indirectly cause startup failures
You didn’t ask directly about account verification, but search intent often includes: “I just moved accounts / new billing / new payment method / new region—why did the DB suddenly stop working?” Here’s what to check.
- Payment method expired or failing: resources may be paused or updates can fail. Verify the payment method under AWS billing.
- Identity verification/KYC not fully completed: certain account changes and provisioning may be delayed or restricted.
- Risk-control review triggered: if AWS flags unusual activity, some operations could be limited. You might see partial provisioning that looks like “DB connection broken.”
- AWS Billing Support Account usage restrictions: if you’re using multiple AWS accounts or sub-accounts, ensure you’re deploying in the same account/region you’re editing.
If you’re operating in a multi-account setup, confirm the Lightsail resources you’re editing belong to the same account profile you’re checking in the console.
Step-by-step fix checklist (printable)
-
Determine DB type:
- Local MySQL/MariaDB → check service status
- Managed Lightsail DB → confirm DB endpoint
-
On the instance, edit the correct
wp-config.phpand verify:DB_HOST(not localhost if DB is remote)- AWS Billing Support
DB_NAME DB_USERDB_PASSWORD
-
Test connectivity from the instance:
nc -vz <DB_HOST> 3306- MySQL login test:
mysql -h <DB_HOST> -u <DB_USER> -p -e "SELECT NOW();"
- If local DB: start/restart MySQL/MariaDB and check logs for disk corruption/outage.
- If managed DB: confirm DB endpoint/user/password after any restore/recreate.
-
Check AWS account/billing state if Lightsail resources changed recently:
- Ensure instance and database are “running/available”
- Verify payment method validity
- Confirm there’s no account verification or risk-control pending message
If you tell me your exact setup, I can narrow it to one fix
Reply with:
- Are you using Lightsail managed database or local MySQL on the instance?
- What is your
DB_HOSTvalue (redact password)? - The exact WordPress error line (or the debug log message if you enabled it)
- Did you recreate the database or change credentials recently?
With that, I can tell you which branch of the troubleshooting tree you’re in (credentials vs endpoint vs service vs account/billing) and the quickest operational correction.

