- Newest
- Most votes
- Most comments
When experiencing frequent "Database connection error" messages with your WordPress WooCommerce application, there are several areas to investigate:
Gather Information: Start by collecting error messages and codes to determine if the errors are intermittent or consistent. Review logs from both your database server and client systems to identify any system-wide issues. Also examine your WordPress configuration files (like wp-config.php) for connection string details.
Verify Network Connectivity: Ensure your WordPress application server can reach your database. Check that both are properly configured within your VPC, verify route tables are correct, and test basic connectivity to the database port (typically 3306 for MySQL/MariaDB or 1433 for SQL Server).
Review Security Configuration: Confirm that security groups allow inbound traffic on your database port from your application server's IP address or security group. Also verify that network ACLs aren't blocking the connection.
Check Database Resources: Monitor your database for resource constraints that could cause connection failures. Look at CPU utilization, available memory, and storage IOPS. Long-running queries or resource-intensive processes can exhaust available connections and cause timeouts.
Verify Authentication: Double-check that your database credentials in WordPress configuration are correct, including username, password, and that the database user has proper permissions.
SSL/TLS Configuration: If your database requires encrypted connections, ensure SSL/TLS is properly configured and that your application supports the required TLS version.
I recommend starting with the AWS Support Center at https://console.aws.amazon.com/support/ to review your specific configuration and get detailed assistance with your setup.
Sources
Troubleshoot RDS for SQL Server connection issues | AWS re:Post
This issue occurs when WordPress cannot connect to the database. Common causes include:
- Database server is unavailable or restarting.
- Incorrect database configuration in
wp-config.php. - Database connection limit has been reached.
- High CPU or memory utilization on the database server.
- Network connectivity issues between the web server and database server.
- Security Group, Firewall, or NACL rules blocking database access.
- Database storage is full.
- Excessive traffic causing connection exhaustion.
Troubleshooting Steps
1. Verify Database Connectivity
Log in to the application server and test connectivity to the database endpoint.
mysql -h <database-endpoint> -u <username> -p
If the connection fails, investigate network connectivity, security groups, or database availability.
2. Verify WordPress Database Configuration
Review the wp-config.php file and ensure the following values are correct:
define('DB_NAME', 'database_name'); define('DB_USER', 'database_user'); define('DB_PASSWORD', 'database_password'); define('DB_HOST', 'database_endpoint');
3. Check Database Availability
If using Amazon RDS:
- Verify the RDS instance status is
Available. - Review RDS events for restarts, failovers, or maintenance activities.
- Check CloudWatch metrics for:
- CPUUtilization
- FreeableMemory
- DatabaseConnections
- FreeStorageSpace
4. Check Database Connection Count
A high number of database connections may prevent new connections from being established.
For MySQL:
SHOW STATUS LIKE 'Threads_connected'; SHOW PROCESSLIST;
Compare the active connections against the configured max_connections value.
5. Verify Security Groups and Network Configuration
Ensure:
- The database security group allows inbound traffic from the application server.
- Network ACLs are not blocking traffic.
- Route tables are correctly configured.
6. Review Web Server Logs
Check Apache/Nginx logs and PHP-FPM logs for database-related errors.
Common messages include:
- Access denied for user
- Too many connections
- Lost connection to MySQL server
- Connection timeout
7. Review Database Logs
Check MySQL or RDS logs for:
- Authentication failures
- Connection exhaustion
- Slow queries
- Deadlocks
- Database restarts
8. Check Server Resource Utilization
Verify that the application server and database server have sufficient:
- CPU
- Memory
- Disk space
Resource exhaustion can cause intermittent database connectivity issues.
answered a month ago
I can see that your website appears to be back online now, but since this issue is intermittent, I'd like to share some guidance to help you identify the root cause and prevent recurrence.
Check Your Database Resources in CloudWatch
Since the error is intermittent rather than constant, the most common cause is your database running out of resources during traffic spikes. Navigate to Amazon CloudWatch and review the following metrics for your database:
CPUUtilization — Look for spikes reaching 100% around the times the error occurs FreeableMemory — Check if memory drops to near zero DatabaseConnections — Determine if you're hitting the maximum connection limit
If you're using a burstable instance class (e.g., db.t3.micro or db.t3.small), also monitor your CPUCreditBalance. Once CPU credits are exhausted, performance degrades significantly, which can directly cause connection failures.
Reference: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/MonitoringAurora.html
Verify Connection Limits and Query Health
Connect to your database and run:
SHOW VARIABLES LIKE 'max_connections'; SHOW FULL PROCESSLIST;
If max_connections is set too low (common on smaller instance classes), any burst of concurrent shoppers will exhaust available connection slots. You can increase this via your DB Parameter Group.
Look for long-running queries stuck in "Sleep" or "Locked" states — these are common with WooCommerce analytics or poorly optimized plugins.
Enable the Slow Query Log to identify problematic queries over time. Reference: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_WorkingWithDBClusterParamGroups.html
Verify Your WordPress Database Configuration
Open your wp-config.php file and check the following:
DB_HOST — If you're using Amazon Aurora, ensure this points to the Cluster Writer Endpoint (not a specific instance endpoint). Using an instance endpoint can cause connection failures during failover events.
Enable WordPress debug logging to capture errors by adding these lines to wp-config.php:
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false );
This creates a debug.log file in /wp-content/ that will show you exactly which component is triggering the database timeout.
Reference: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.Connecting.html
Review Timeout Configurations
Ensure your timeout settings are aligned across the stack:
MySQL: wait_timeout, interactive_timeout PHP: max_execution_time Web Server (Nginx/Apache): Proxy timeout / keepalive_timeout
If a timeout at one layer silently drops an idle connection, WordPress may attempt to reuse a stale connection and throw the "Database connection error."
Recommended WooCommerce Optimizations
Database Cleanup — Remove expired transients, old cart sessions, and post revisions to reduce table bloat Scale Your Instance Class — Move from burstable (db.t3) to memory-optimized (db.r6g) for consistent performance under load Aurora Auto Scaling with Read Replicas — Distributes read-heavy traffic during peak periods Reference: https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/WhatIs.html Reference: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.Integrating.AutoScaling.html
Next Steps
If the issue persists after reviewing the above, further troubleshooting would require examining your specific resource-level details such as CloudWatch metrics, database event logs, parameter group configurations, and instance specifications. If you have an AWS Support plan (Developer, Business, or Enterprise), I'd recommend opening a technical support case through the AWS Support Center (https://console.aws.amazon.com/support/home) so that an engineer can review your account-specific resources and provide targeted guidance.
Relevant content
asked 3 years ago
