Kā labot kļūdu, izveidojot datu bāzes savienojumu WordPress sistēmā

The “Error establishing a database connection” message in WordPress is a common issue that indicates your website is unable to connect to the database. This problem can be caused by several factors including incorrect database information in your WordPress settings, a corrupted database, issues with your web hosting server, or an overloaded or malfunctioning database server. Here’s how to troubleshoot and fix this error:

Check the WordPress Database Credentials

The most common reason for this error is incorrect database credentials in your WordPress configuration file (wp-config.php). This file contains the database name, username, password, and server that must match what’s set in your hosting account.

  • Access your website files using FTP or the File Manager in your hosting control panel.
  • Locate and edit the wp-config.php failu.
  • Check the DB_NAME, DB_USER, DB_PASSWORD, un DB_HOST values. Ensure they match the database information provided by your hosting provider.
define('DB_NAME', 'database_name_here');
define('DB_USER', 'username_here');
define('DB_PASSWORD', 'password_here');
define('DB_HOST', 'localhost');
  • If any values were incorrect, update them and save the changes. Then, check your website again.

Check Your Database Host Information

Sometimes the database host information changes, especially if your website is on a managed WordPress hosting platform. If DB_HOST is set to localhost and you’re still experiencing issues, contact your hosting provider to confirm the correct database host information.

Repair WordPress Database

If the database is corrupted, WordPress has a built-in feature to repair it.

  • Add the following line to your wp-config.php file just before /* That's all, stop editing! Happy publishing. */:
define('WP_ALLOW_REPAIR', true);
  • After adding this line, visit http://yourwebsite.com/wp-admin/maint/repair.php (replace yourwebsite.com with your actual domain name).
  • Noklikšķiniet uz Repair Database vai Repair and Optimize Database button. WordPress will attempt to repair your database.
  • Important: Remove the line from your wp-config.php after the repair is done for security reasons.

Check Your Web Hosting Server

If your database credentials are correct and your database isn’t corrupted, the issue might be with your web hosting service.

  • The server might be down, or there might be a problem with the database service. Contact your hosting provider to check if there are any server-related issues.
  • If your website has recently experienced a surge in traffic, your database server might be overwhelmed. Your hosting provider can confirm this and suggest upgrading your hosting plan if needed.

Rezerves kopijas atjaunošana

If you’re unable to resolve the issue and you have a recent backup of your website, consider restoring it. Sometimes, restoring your website to a previous state when it was working correctly can fix the problem. Ensure you have a backup of your WordPress files and database before proceeding.

Update WordPress Site URL

In some cases, especially after a site migration or domain change, updating the WordPress site URL directly in the database can resolve connection issues. This should be done with caution and is recommended for advanced users:

  • Access your database via phpMyAdmin from your hosting control panel.
  • Go to the wp_options tabula. Meklējiet siteurl un mājas lapa rindas.
  • Pārliecinieties, ka šajās rindās ir norādīts pareizais vietnes URL. Ja tas tā nav, rediģējiet tās.

Secinājums

Ziņa "Kļūda datubāzes savienojuma izveidē" var būt nomācoša, taču, metodiski veicot šos problēmu novēršanas soļus, varat identificēt un atrisināt problēmu. Pirms jebkādu izmaiņu veikšanas tīmekļa vietnē vai datubāzē vienmēr pārliecinieties, ka ir izveidota nesen veikta dublējuma kopija. Ja problēma saglabājas arī pēc šo soļu izmēģināšanas, iespējams, ir pienācis laiks konsultēties ar WordPress izstrādātāju vai saņemt papildu palīdzību no hostinga pakalpojumu sniedzēja.