Database connection error and wp-config settings check

After the WordPress migration, the screen suddenly displayed “Error establishing a database connection.” The domain was successfully moved to the new address, so why is the site unable to find the database?

The perpetrator is surprisingly hidden not in the domain itself, but within the announcement. The first possibility is that one of the four pieces of information connecting the new server and database is incorrect.

This error indicates that the process stopped at the database stage.

This message indicates that WordPress was unable to connect to the database before attempting to generate the page. Because it cannot access the database, where the content, settings, and user information are stored, it is unable to create the page.

This is different from a domain name issue.

The `wp-config.php` file is located in the outermost directory of the WordPress installation folder. This file is a crucial configuration file that specifies which database the site will use and with what account credentials.

There are four basic values that need to be verified.

  • DB_NAME: Database name.
  • DB_USER: Database user name.
  • DB_PASSWORD: The password for that user.
  • DB_HOST: Database server address.

There is a reason why the number of errors increases immediately after a migration.

When migrating a server, it is common to copy both the files and the database. However, the database name or user name may be different on the new hosting environment.

The house has been moved, but the key remains the same. The door is now in the new house.

The official WordPress migration guide explains that if the database name or the user changes, the values in wp-config.php must be changed to the new values. If the database server has been moved to a different location, the DB_HOST value may also be different.

Specifically, DB_HOST may not simply refer to a server name. It may also include the port number specified by the hosting provider, or the path to a Unix socket.

Therefore, immediately after a migration, it is easy to suspect the domain name. However, the first thing to check is not the address bar.

Let’s start by looking at the connection information.

The fastest way is to compare your values line by line.

Immediately after the migration, do not change the domain settings. First, you must verify that the four values in wp-config.php match the actual information of the new database.

Do not rely on memory when entering values. Open the database management screen of the new hosting service and compare each item one by one with the wp-config.php file.

  1. It checks whether the value of DB_NAME is the same as the new database name.
  2. Checks whether the user “DB_USER” is the same as a new database user.
  3. It checks whether the value of DB_PASSWORD is the password for that user.
  4. It checks whether the `DB_HOST` value matches the server address and port requirements.

If even one of the values is different, WordPress may fail to find the database or may fail authentication. Having similar names does not mean the values are the same.

Even a single character difference can prevent it.

Next, the system checks whether the database user has the authority to access the specified database. Even if the information matches, access will be denied again if the user lacks the necessary permissions.

The order is important because the site address setting and the connection setting are located in different places. The “home” and “siteurl” values are stored in the wp_options table within the database, and they are independent of your connection settings.

Thinking that it can be resolved simply by modifying the configuration file is a dangerous assumption.

Even if you modify the wp-config.php file, the error may persist. If the database capacity has been exceeded or the database server itself has stopped, you will need to contact your hosting provider.

At this time, many people continue to modify the file. However, if the four values are already correct, repeated modifications may not help to find the cause, but rather may eliminate potential clues.

When resolving issues directly, the main points of difficulty often involve permissions and server status. While a user may be able to open a file, it may be necessary to check with the hosting management team to determine whether the user has the necessary permissions to connect to the database, and whether the server is running.

Before checking permissions and server status, it is also necessary to create a recovery point for the migration task itself. The LUX Content Migration “Whole site backup / restore” add-on backs up and restores the database, theme, plugins, uploaded files, and settings into a single file. This feature is not intended to determine the cause of incorrect access information, but rather to prepare a baseline for reverting the migration process if necessary.

Based solely on the file, it is not possible to determine the server’s status.

It is important to avoid adding new character settings such as DB_CHARSET or DB_COLLATE without a valid reason. Attempting to fix connection errors can inadvertently affect other settings.

RELOCATE is not a universal solution for all problems. It is only a temporary measure to adjust the site URL to a new address, and it does not resolve database connection errors.

There is an official announcement stating that leaving this constant after the task is completed may cause security issues. It is best to keep address-related issues and connection issues separate and not mix them together.

It is necessary to distinguish between cases where the screen does not open and cases where only the address is incorrect.

If the screen does not open immediately after transferring the files and database, follow these steps:

  • First, back up the original wp-config.php file.
  • Compare the connection values with the new hosting information.
  • Verify the database user permissions.
  • Check the status of the database server and its capacity.

If the database name, username, password, or server address has changed, modify only those specific items with the new information. There is no need to change any settings that have not been altered.

Please only modify the changed values.

Conversely, if the connection is successful but the website redirects to an old address or links are broken, do not assume it is a database connection error. You must check the `siteurl` and `home` settings in the `wp_options` table separately.

After changing the domain, when searching for and replacing URLs, it is not acceptable to blindly replace strings throughout the entire database. Because serialized data may be corrupted, you must use tools specifically designed for WordPress.

If the database, domain, name, and user all remain unchanged, it is often possible to avoid modifying the wp-config.php file. If the settings are correct but the issue persists, ask the hosting provider to check the service status, storage limits, user permissions, and connection ports.

Ultimately, the key is to first categorize the types of errors.

Dividing the migration scope using LUX Content Migration.

It is safer to separate the tasks of checking for database connection errors and determining the scope of content and settings to be migrated. LUX Content Migration is a plugin that exports posts, pages, comments, authors, and settings from an existing WordPress site into a dedicated .wpmpx file, allowing them to be transferred to another WordPress site.

When moving content only, you can select posts, pages, categories, comments, authors, custom fields, and media under “Content only.” When moving settings only, “Site settings only” handles general, reading, and discussion settings, permalinks, widget placement, and menu structure separately. Before importing, use Preview to check the posts and comments that will be created and the number of images required, and you can also use ↩ Roll back for a completed category to delete newly created posts and undo the operation.

Frequently Asked Questions.

Q. If I change the domain name and encounter a database connection error, should I fix the domain name first?

A. No.

First, verify that the values for DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST are correct for the new hosting information. After confirming that the connection is working properly, check the address settings separately.

Q. What should you do if you have adjusted all four values, but the error persists?

A. The database server may have been stopped or may have exceeded its capacity. Do not repeatedly modify the files; instead, contact the hosting provider and request them to check the server status and user permissions.

Q. Can this problem be easily solved using a tool? What kind of tool should be used?

A. Connection information verification can first be checked using only the hosting management screen and the original backup. Changing the URL requires using a tool specifically designed for WordPress that takes into account serialized data.

Q. Can the content and site settings to be migrated be moved separately?

A. It is possible.

LUX Content Migration allows you to specify the scope of content and site settings migration separately, with options for “Content only” and “Site settings only.” Before importing, you can preview the posts and comments that will be created, as well as the number of images required, and then proceed with the import.

WordPress-related links

https://store.luxdigest.com
https://wpcm.luxdigest.com
https://sohoseo.luxdigest.com