WordPress Troubleshooting: Error Establishing a Database Connection

Trending 2 years ago

In this post, we’ll quickly reappraisal nan communal causes of nan WordPress correction establishing a database connection. Then we’ll supply you pinch a step-by-step guideline connected really to troubleshoot and repair it. 

WordPress errors are ever frustrating erstwhile they arise. The bully news pinch this peculiar 1 is this: The Error establishing a database connection tells america wherever nan rumor occurred. This will importantly trim down connected really overmuch troubleshooting you’ll person to do to hole it.

Why Won’t WordPress Connect to nan Database?

When you brushwood an correction codification that sounds “Error establishing a database connection”, it intends your website can’t fetch nan information from your website. Since WordPress uses a database to shop each of your website contented and data, it needs to link to it successful bid to tally nan site. 

Fortunately, you’re apt to drawback this correction earlier it affects your website visitors. So agelong arsenic you person caching installed, your website should proceed to show your web pages without rumor until you modify something. 

However, you will suffer entree to nan backend WordPress dashboard until this correction is resolved. 

So, what causes it? There are a number of reasons why you’ll spot this error:

  • Your database login specifications are wrong.
  • The website URL is incorrect.
  • The database tables person been corrupted. 
  • WordPress files person been corrupted.
  • The server is down aliases overloaded. 
  • Your tract has been hacked.

This benignant of correction — sloppy of nan root of nan problem — needs to beryllium fixed immediately. And not conscionable because you won’t person entree to your site. 

When your tract inevitably goes down and visitors spot nan connection “Error establishing a database connection”, it’s going to scare a batch of them away. It’ll origin others to mobility nan information and/or legitimacy of your site. 

To protect your marque integrity arsenic good arsenic your website’s postulation and sales, hole nan correction arsenic soon arsenic you spot it.

How to Fix nan WordPress Error Establishing a Database Connection

In bid to hole this WordPress error, you’ll request entree to your server and files. It’s okay if you’ve ne'er made modifications to your files aliases database before. We’ll show you wherever to spell to instrumentality each of these solutions.

We’ll beryllium utilizing SiteGround web hosting to show these repairs. While your hosting dashboard whitethorn look a small different, nan basal steps will beryllium much aliases little nan same.

Solution #1: Update Your Database Login Details

In bid for your WordPress tract to link to nan MySQL database, WordPress needs nan pursuing information:

  • database name
  • database username
  • database password
  • database big name

WordPress stores these login specifications successful nan wp-config.php file, which is located successful nan archive guidelines of your website. You tin edit nan wp-config.php by connecting to your tract pinch an FTP customer aliases you tin usage cPanel if it is supported by your host.

In SiteGround (or immoderate your hosting supplier is), spell to Site Tools > Site > MySQL first. 

Your database sanction is nether Name. Click nan # User nexus to uncover nan username. Note these down somewhere.

Go to File Manager (or FTP Accounts, if you person one) next. 

Click connected public_html to position nan documents stored astatine your website’s root. Scroll down nan database until you find wp-config.php

Click nan Edit button aliases double-click it to unfastened nan file. Your login specifications will look for illustration this: 

1 /** The sanction of nan database for WordPress */
2
3 define( 'DB_NAME', 'fakedbname' );
4
5 /** MySQL database username */
6
7 define( 'DB_USER', 'fakeusername' );
8
9 /** MySQL database password */
10
11 define( 'DB_PASSWORD', 'fakepasswordpassword' );
12
13 /** MySQL hostname */
14
15 define( 'DB_HOST', 'localhost' );

Start by comparing nan database sanction and username to nan ones you conscionable copied from MySQL. If they’re wrong, that’s apt why WordPress can’t link to nan database. 

Before you make immoderate changes to this file, prevention a backup of your website. Even if nan website is down owed to nan relationship error, nan rumor could beryllium exacerbated if nan correction isn’t decently fixed. 

So it’ll beryllium useful being capable to rotation backmost to this constituent earlier you’ve altered anything. Here’s what you’ll do to backmost up your WordPress site.

Back to nan wp-config file. If nan first 2 values are incorrect, edit them and past click Save

Return to your website to spot if this fixed nan issue. If it did not, nan password could beryllium nan issue. 

Instead of trying to way down nan encrypted password, spell backmost to nan MySQL Manager and click connected nan Users tab astatine nan top. Click connected nan vertical ellipsis connected nan acold correct and prime Change Password

With your password updated, you tin return to your File Manager aliases FTP and update nan password successful nan wp-config record to match. 

Save your changes. Then return to your WordPress tract erstwhile much to spot if this fixed nan issue.

Solution #2: Fix nan Site URL

If nan rumor remains unresolved, nan adjacent point to cheque successful nan database is your tract URL. 

For this one, spell to MySQL > PHPADMIN and click nan ACCESS PHPMYADMIN button.

Click connected nan Databases tab astatine nan top. If you person much than 1 database, prime nan superior 1 for your site. 

The array you’re looking for is commonly called wp_options. However, yours mightiness person a different prefix. Use nan hunt barroom astatine nan apical of nan page to find tables pinch nan connection “options” successful it to find yours. 

Select nan _options file. Click to unfastened it. At nan apical of nan database of details, you should spot siteurl.

Confirm that nan option_value matches your domain name. If it doesn’t, click nan Edit button connected nan near to alteration it. 

Reminder: If you haven’t made a backup of your tract yet, do truthful now earlier editing this table. 

When you’re done, prevention your changes. Then return to your website to spot if nan correction is gone.

Solution #3: Activate Repair Mode

In immoderate cases, nan database has been corrupted. This tin hap if you adhd and region a batch of themes aliases plugins and nan information doesn’t get wholly cleared retired aliases an correction occurs on nan way. 

To repair nan damage, you tin usage WordPress’s repair mode. 

Go backmost to Site > File Manager aliases FTP Accounts. Open and edit nan wp-config.php record erstwhile more. 

Locate nan following:

1 /* That's all, extremity editing! Happy blogging. */

Directly supra it, adhd this statement of code:

1 define('WP_ALLOW_REPAIR', true);

Save your changes. 

Open a caller tab successful your browser and participate nan following: 

https://yourdomain.com/wp-admin/maint/repair.php

Replace yourdomain with your existent website’s domain name. Then click nan Repair Database fastener that appears. 

Once repair mode has completed, sojourn your website erstwhile much to cheque for nan relationship error. 

Whether aliases not nan correction has been removed, you’ll request to spell backmost to nan wp-config.php record to delete nan repair mode string. Save your changes erstwhile you’re done to return your tract retired of repair mode.

Solution #4: Check For and Replace Corrupted Files

Theme and plugin conflicts and record corruptions tin happen. So excessively tin issues pinch nan WordPress software. So if thing other has worked until now, it’s clip to spot what happens erstwhile you put these files to nan test.

Test Your Theme

From your File Manager aliases FTP, look for a files called wp_content. This is wherever some your themes and plugins are stored. 

Locate nan files called themes

Right-click nan files sanction and click Rename. Change it to old-themes. This will unit WordPress to deactivate your existent taxable and alteration nan default 1 successful its place. 

Check your website to spot if that fixed nan issue. If it did, past nan latest type of your taxable is conflicting pinch a plugin aliases pinch WordPress. 

To spot if it’s a plugin conflict, rename nan files backmost to themes. Then proceed pinch nan plugins test.

Test Your Plugins

Go to nan plugins folder and do nan aforesaid thing. Change nan sanction to old-plugins. Again, this will deactivate each your WordPress plugins. 

Check your tract erstwhile more. If nan rumor has been resolved, that intends that 1 of your plugins (or a caller update of 1 of them) is conflicting either pinch different plugin, nan theme, aliases WordPress itself. 

Since you tin now log into WordPress, spell to nan Plugins panel. Reactivate each plugin 1 astatine a time. Refresh your tract to spot if it remains live. If it does, past you tin transverse that plugin disconnected your list. 

Deactivate that plugin and past move onto nan adjacent one. Repeat this process until you’ve tested each plugin connected its own. 

If location are nary issues astatine this point, nan rumor isn’t a plugin/theme conflict. So it mightiness beryllium 2 plugins conflicting. You’ll request to activity your measurement done different pairings to spot wherever nan rumor lies. 

To much efficaciously hone successful connected nan issue, interaction your web hosting support to spot if they tin show you which of your plugins were astir precocious updated (in lawsuit you don’t remember). That’ll thief you pinpoint nan conflict. 

Once you’ve recovered nan issue, you tin either rotation nan plugin backmost to nan erstwhile type that useful aliases find an replacement solution. It’s besides a bully thought to notify nan plugin developer and/or taxable developer of nan issue.

Test WordPress

If thing other has worked, past nan problem could beryllium WordPress aliases nan latest type of it. 

Unfortunately, successful bid to hole this benignant of error, you’re going to person to switch nan halfway type of nan software. While it won’t impact nan main contented of your site, it will erase immoderate civilization coding you’ve done aliases changes you’ve made successful the wp-config.php aliases .htaccess files. 

If you’re uncomfortable pinch doing this step, that’s not a problem. Move to nan adjacent solution.

To switch WordPress, Get WordPress from nan WordPress.org site. Download nan latest type of nan software. 

Unzip nan file. Delete nan wp-config-sample.php record on pinch nan wp-content folder. 

You’ll request FTP entree to your halfway to upload nan caller WordPress file. If you don’t person it yet, you tin create an FTP Account successful SiteGround. Then usage FileZilla to upload and switch nan WordPress halfway files. 

When you’re done, cheque your WordPress tract to spot if nan correction is resolved. If it is, you tin reconstruct each of your themes and plugins to wherever they were previously.

Solution #5: Restore Your Last Backup

If WordPress still fails to found a database connection, past you’ll want to rotation it backmost to nan past saved type of nan database. 

There are different devices WordPress users usage to seizure website backups. You mightiness beryllium utilizing WordPress backup plugins for illustration UpdraftPlus and Jetpack. Or you could beryllium utilizing your web hosting’s backup service. 

For this example, we’ll usage SiteGround’s backups to rotation your database back. 

In SiteGround, spell to Site Tools > Security > Backups. Scroll down to nan database of backups. 

Click nan vertical ellipsis to nan correct of nan astir caller backup (i.e. not nan 1 you saved while troubleshooting today). Select nan Restore Databases option.

Select nan database aliases databases you want to restore. Check nan container stating that you understand nan action you’re astir to take. Then click Confirm

After nan backup restoration process is done, sojourn your website to spot if nan correction is gone. If it is, past thing that took spot betwixt now and that past backup caused nan issue. 

If you’re unsure of what that mightiness beryllium (like a plugin update, a squad personnel poking around, etc.), get successful touch pinch your hosting provider. They should beryllium capable to return a look successful your logs and fig retired what went wrong.

Solution #6: Contact Your Web Host

If you person travel this far, past nan past point you tin do is to interaction your web host’s support team. There are further issues that tin origin nan Error establishing a database connection to look and only they will beryllium capable to help. 

For example: 

  • The servers are down aliases undergoing maintenance. 
  • Your database reached aliases exceeded its limit owed to excessive traffic.
  • Your website has been hacked. 

When you interaction support, fto them cognize nan rumor you’re seeing erstwhile you effort to entree WordPress aliases your website. Send them a screenshot of nan correction connection if possible. Also explicate nan solutions you’ve tried up until this point. 

This will prevention clip arsenic they constrictive down nan rumor and activity to get it resolved for you.

Conclusion

It’s stressful whenever an correction appears connected your website. One day, everything’s moving fine. The next, you’ve mislaid entree to WordPress and your visitors are being shown a blank page and correction message. 

Thankfully, we cognize wherever nan root of this WordPress error establishing a database connection lies. This will make it a full batch easier to find what’s causing it.

Time is of nan principle erstwhile it comes to WordPress errors, particularly 1 for illustration this that whitethorn scare distant visitors. Once you place what nan correction is, activity your measurement done nan six solutions supra truthful you tin get your website restored arsenic soon arsenic possible. 

Did you find this station useful?

Suzanne Scacca

Tampa, FL

Suzanne Scacca is connected a ngo to make nan web a amended place. That's why she specializes successful topics related to UX champion practices, mobile creation strategies, and ethical marque and business choices. She besides draws connected her first-hand acquisition successful nan design, marketing, and firm worlds to tackle subjects from an insider's perspective. While she useful arsenic a freelance writer successful nan web creation and exertion spaces now, Suzanne antecedently had a decade-long profession moving arsenic a task manager, during which clip she worked for companies for illustration Amazon and Disney. At nan extremity of that career, she was tasked pinch rebuilding a failing web creation agency. After nan successful relaunch of nan company, she decided to motorboat a penning business of her ain truthful she could standard her scope and thief companies each astir nan world amended their strategies, processes, and outcomes.

More
Source Tuts Plus
Tuts Plus