Tag - Connection

How to Fix the Error Establishing a Database Connection in WordPress

Are you seeing the ‘Error establishing a database connection’ notice on your WordPress website? It is a fatal error that makes your WordPress website inaccessible to the users.

This error occurs when WordPress is unable to make a connection to the database. A number of things can affect your WordPress database connection which makes it a bit difficult for beginners to troubleshoot.

In this article, we will show you how to easily fix the error establishing a database connection in WordPress.

Fixing the database connection error in WordPress

What Causes Error Establishing a Database Connection in WordPress?

The ‘Error establishing a database connection’ issue can be caused by incorrect database information in your WordPress settings, corrupt database, or an irresponsive database server.

Database connection error in WordPress

A database is a software which makes it easy to store, organize, and retrieve data into other software.

As a content management system, WordPress uses a database to store all your content and other website data. It then connects to the database each time someone visits your website.

WordPress needs the following information for connecting to the database:

  • Database name
  • Database username
  • Database password
  • Database server

This information is stored in your WordPress configuration file called wp-config.php.

If any of these items are incorrect, WordPress would fail to connect to your database server, and you’ll see the ‘Error establishing a database connection’ error.

It is one of the most common WordPress errors. Apart from incorrect credentials, this error can also appear if the database server is down, or the database files are corrupt.

Let’s take a look at how to fix error establishing database connection issue in WordPress with step by step troubleshooting.

1. Check Your WordPress Database Credentials

The most common reason for database connection error in WordPress is incorrect database credentials. If you have recently moved your WordPress site to a new host, then this could be the most likely reason.

Your WordPress database credentials are stored in the wp-config.php file. It is the WordPress configuration file that contains important WordPress settings including database information.

If you have not edited wp-config.php file before, then take a look at our guide on how to edit wp-config.php file in WordPress.

You’ll be looking for the following lines in the wp-config.php file.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

You need to make sure that the information for the database name, username, password, and database host is correct.

You can confirm this information from your WordPress hosting account dashboard. Simply log in to your hosting account and click on MySQL databases under the database section.

Database information

This will take you to the database management page in your hosting dashboad. From here, you can find out your database name and the username.

Database name and username

Below that you will find the database users and links to change the user password.

Changing database user password

Once you have confirmed your database name, username, and password, you can change that information in your wp-config.php file if needed.

After that, try visiting your website again to see if the database connection error has gone.

If you can still see the error, then this means that something else is wrong. Continue reading for more troubleshooting steps.

2. Check Your Database Host Information

If you are confident that your database name, username, and password information is correct, then you may want to make sure that you are using the correct database host information.

Most WordPress hosting companies use localhost as your database host. However, some managed WordPress hosting companies use separate servers to host databases. In that case, your database host information will not be localhost.

You need to contact your WordPress hosting company to confirm your database host information.

3. Repair WordPress Database

If you are getting a different error on the wp-admin, for instance, something like “One or more database tables are unavailable. The database may need to be repaired”, then you need to repair your database.

You can do this by adding the following line in your wp-config.php file. Make sure to add it just before ‘That’s all, stop editing! Happy blogging’ line wp-config.php.

define('WP_ALLOW_REPAIR', true);

Once you have done that, you can see the settings by visiting this page: http://www.yoursite.com/wp-admin/maint/repair.php

Repair WordPress database

Note: the user does not need to be logged in to access the database repair page. Once you are done repairing and optimizing your database, make sure to remove this code from your wp-config.php.

4. Check if Your Database Server is Down

If everything seems to be correct, and WordPress still cannot connect to the database, then your database server (MySQL server) may be down.

This could happen due to heavy traffic on a server. Basically, your host server just cannot handle the load (especially when you are on shared hosting).

Your site will get really slow and for some users it may even output the error. So the best thing you should do is get on the phone or live chat with your hosting provider and ask them if your MySQL server is responsive.

If you have other websites running on the same server, then you can check those sites to confirm that your SQL server is down.

If you do not have any other site on the same hosting account, then simply go to your hosting dashboard and try to access phpMyAdmin and connect the database.

If you can connect, then we need to verify if your database user has sufficient permission. Create a new file called testconnection.php and paste the following code in it:

$link = mysqli_connect('localhost', 'username', 'password');
if (!$link) 
die('Could not connect: ' . mysqli_error());

echo 'Connected successfully';

Make sure to replace the username and password. You can now upload this file to your website and access it via web browser.

If the script connected successfully, then it means that your user has sufficient permission, and there is something else that is wrong.

Go back to your wp-config file to make sure that everything there is correct (re-scan for typos).

Other Solutions That Have Worked for Users

If the above-mentioned troubleshooting tips failed to fix the database connection error on your website, then you may try these additional steps.

Reported by our users, these steps have helped some users resolve the database connection error on their websites.

1. Update WordPress Site URL

Try updating the WordPress site URL using phpMyAdmin. Simply access phpMyAdmin from your hosting account dashboard, and select your WordPress database.

Running SQL in phpMyAdmin

After that click on the SQL menu on the top and enter the following MySQL query.

UPDATE wp_options SET option_value='YOUR_SITE_URL' WHERE option_name='siteurl'

Don’t forget to provide your own site URL and change wp_options to your own table name as you may have changed the WordPress table prefix.

2. Rebooting Web Server

Users on dedicated servers, local server, and virtual private servers (VPS) can try rebooting their servers.

This will restart your web and database server which may fix some temporary glitches causing the error.

3. Ask for help

If everything else fails, then you may need to contact your web hosting company. All good WordPress hosting companies will help you troubleshoot the problem, point you in the right direction, or even fix it for you.

You can also hire WordPress developers from Codeable that can help you fix this issue for reasonable rates. The best part is that these developers are highly-vetted by Codeable team, so you know they can be trusted.

We hope this article helped you fix the error establishing a database connection in WordPress. You may also want to see our WordPress troubleshooting guide for tips on resolving WordPress issues on your own.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Fix the Error Establishing a Database Connection in WordPress appeared first on WPBeginner.

Source link

How to Fix Your Connection is Not Private Error (Site Owners Guide)

Are you seeing ‘Your connection is not private’ error on your WordPress website? This is the error message you’ll see on Google Chrome.

The same error will be displayed on all modern browsers with slightly different messages, and it can be a bit confusing for beginners to troubleshoot.

In this site owner’s guide, we’ll show you how to easily fix ‘Your connection is not private’ error on your website. We’ll also talk about why this error appears, and how you can avoid it in the future.

Fixing your connection is not private error in WordPress

What is ‘Your Connection is Not Private’ Error?

‘Your connection is not private’ error appears on websites using the SSL / HTTPs protocol when your browser is unable to validate the SSL certificate issued by the website.

Basically, any website using SSL / HTTPs protocol sends a security certificate information to users browsers upon each visit. Browsers then try to validate the certificate using the public key accompanying the certificate.

If it checks out, then users browser encrypts the data using the private key sent by your website. This encryption secures the data transfer between a user’s browser and your website.

How SSL works to protect data transfer

However, if the browser is unable to validate the certificate, then it cannot transfer the data securely and displays the error that your connection to the website is not private.

This is a common SSL error and appears on all modern browsers with slightly different error messages.

Google Chrome

Google Chrome will show this error as ‘Your connection is not private’.

Your connection is not private error in Google Chrome

Mozilla Firefox

Firefox would show this error as ‘Your connection is not secure’.

Connection not secure error in Google Chrome

Microsoft Edge

Microsoft Edge browser displays it with the ‘Your connection isn’t private’ or ‘This site isn’t secure’ error message.

This site is not secure - Microsoft Edge

Safari, Brave, and other browsers will display similar messages.

Why This Error Message Occurs?

Now you may be wondering, what caused ‘Your connection is not private’ error to appear on your website. This error is peculiar because in many cases it may show up without you making any changes to your website.

It can be caused by several reasons. For instance, if a user’s computer clock is out of sync, then it may show the certificate as expired.

Another scenario is that a certificate previously issued by your website is stored in user’s browser. The private key sent by your website does not match the old certificate and the browser fails to validate the secure connection.

Last but not least, the most obvious reason you’d see this error is if the SSL certificate on the website has expired.

The following are the steps you can take to fix the ‘Your connection is not private’ error. You can also try these steps even when the error is appearing on other websites as well.

1. Force Reload a Page

Reload a page

The first step is to try turning it on and off method. Start by simply shutting down the browser app and then reopening it.

After that, try to visit the website. If you can still see the error then try force reloading the page. Use Command + R keyboard shortcut on Mac or CTRL + Reload button on Windows.

This will force the browser to ignore the cached version of the page and load the latest version.

2. Check with Multiple Browsers

Test in multiple browsers

If you are only checking it with one browser on the same machine, then try visiting the website using any other browser app.

This step will eliminate the possibility that the issue is limited to a specific browser. If it is, then reinstalling that browser would fix the issue.

Otherwise, you can move on to try the next steps in this guide.

3. Clear Your Browser Cache

Clear your browser cache

You may have heard this as the first advice for many internet and website-related issues. It is true in this case too. Your browser may be loading files from an older version of your website which may be triggering the issue.

We have a complete guide on how to clear browser cache for all major browsers with step by step instructions.

Once you have cleared the cache, try visiting the website again to see if the issue has resolved. If it hasn’t, then continue reading.

4. Check Your Computer’s Clock

Normally, your computer syncs its date and time settings automatically. However, if your computer has incorrect date/time settings, then this may cause your browser to think that a website’s SSL certificate is invalid.

Sync Date / Time on Windows Computers

If you are using a Windows computer, then simply right click on the taskbar and select ‘Adjust Date and Time settings’.

Adjust date and time in Windows

This will open date and time section in the Windows Settings app. Make sure that your computer’s date and time is correct and ‘Set time automatically’ option is checked.

Date and time settings are turned on to automatically sync

Sync Date / Time on Mac Computers

If you are using a Mac computer, then open the ‘Settings’ app and click on the ‘Date & Time’ icon.

Date and time settings in Mac

Next, switch to the Date & Time tab and make sure that the option next to the ‘Set date and time automatically’ option is checked. If it is not checked, then click on the padlock icon at the bottom left corner of the window to enable this option.

Sync date and time and settings in Mac

5. Turn off Antivirus and VPN Apps

If you are using any antivirus programs on your computer or a VPN service, then you may want to temporarily turn them off.

This would allow you to verify that these apps are not blocking the SSL certificate and forcing your browser to show the ‘Your connection is not private’ error.

If you discover that one of these apps was causing the problem, then you can reach out to their support team for help.

6. Check Your SSL Certificate Expiration

Another common reason for this error is expired SSL certificates. These certificates are issued for a specific period and expire when they reach the end of that period.

You can check your certificate’s expiration date by clicking on the padlock icon next to your website and selecting the certificate option.

Checking a website's SSL certificate details

This will bring up your SSL certificate details. You can clearly see certificate expiration date in the window.

SSL expiry date

Most domain registrars and SSL certificate providers will automatically notify you when your SSL certificate needs to be renewed.

If you are using a free SSL certificate, then most WordPress hosting companies have scripts in place that automatically renew them upon expiration.

However, those mechanisms may fail and your SSL certificate may expire. Don’t worry, you can easily fix that by simply replacing your SSL certificate.

Instructions to do that may vary depending on your certificate provider and hosting company. In fact, many hosting companies will update it for you upon request.

7. Test Your SSL Server

SSL test tool

If you have been setting up your SSL certificate manually by yourself, then you may want to make sure that all configuration settings are working properly.

To do that you can run an SSL server test. This test allows you to check the complete SSL set up of your website.

This includes TLS protocol, cross-browser testing, and SSL/HTTPs set up checks. The scanner will also provide you detailed information about each test.

8. Check Certificate Domain Name

You can set up your SSL certificate to work for different variations of a domain name. For example, www and non-www URLs.

If your certificate is only set up for one variation of your domain name, and you access the website using another variation, then this would result in ‘Your connection is not private’ error. Google Chrome will show the error code as SSL_ERROR_BAD_CERT_DOMAIN.

This error could also appear if you have recently moved your website to a new domain name or server.

One easy solution is to issue a free SSL certificate for both variations of your domain name. You can request your hosting provider to do that for you.

Another solution is to redirect your website visitors to the correct variation of your domain name. See our article, on how to set up redirects in WordPress for more details.

We hope this article helped you learn how to fix ‘Your connection is not private’ error in WordPress. You may also want to bookmark our guide on fixing the most common WordPress errors.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Source link