Fix error setting up database connection in WordPress second part

Fix error setting up database connection in WordPress second part

Check your wordpress database credentials

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

Your WordPress database credential is stored in the wp-config.php file. This is a WordPress configuration file containing important WordPress settings including database information.

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

1
2
3
4
5
6
7
8
9
// ** 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 can verify this information from your WordPress hosting account panel. Just log into your hosting account and click on MySQL database under the data section.

This will take you to the database management page in your hosting dashboard. From here, you can find the name and username of your database.database users and links to change the user password.

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

After that, try again on your website to see if a database connection error has occurred.

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

Check your database host

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

Most WordPress hosting companies use some WordPress hosting companies use separate servers to host the database. In this case, your database host will not be local.

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

Repair wordpress database

For example, if you get another error in wp-admin, “One or more databases are unavailable. Your database needs to be repaired, ”your database needs to be restored.

You can do this by adding the following line to your wp-config.php file: ‘All this, add it, make sure you add it immediately before you stop editing. Congratulations bloggers wp-config.php

1
define('WP_ALLOW_REPAIR', true);

Check if your database server is down

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

This can happen due to heavy traffic on the server. Basically, your host server just can’t handle the load (especially when you’re on shared hosting).

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

If you have other websites running on the same server, you can check those sites to see if your SQL Server is down.

If you do not have another site on the same hosting account, just go to your hosting dashboard and try to access phpMyAdmin and connect to the database.

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

<?php
$link = mysqli_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>

Be sure to change the username and password. Now you can upload this file on your website and access it through a web browser.

If the script is successfully attached, it means that your user has enough permission, and there is something else that is wrong.

Other solutions that work for users

If the above troubleshooting tips failed to fix a database connection error on your website, you can try these additional steps.

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

submit questions and problems

Leave a Reply

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