انتقل إلى المحتوى

الدروس استكشاف الأخطاء وإصلاحها مبتدئ1 دقائق قراءة

How to Fix "Error Establishing a Database Connection"

WordPress can’t reach its database. Check credentials in wp-config.php, the database server, user privileges and corrupted tables, step by step.

بواسطة فريق تحرير ZSOLNET آخر تحديث

هذه الصفحة غير متاحة بالعربية بعد، لذا تُعرض بالإنجليزية.

أهم النقاط

  • Wrong credentials in wp-config.php cause most database connection errors.
  • The database user must be assigned to the database with privileges.
  • After migrating, update wp-config.php with the new database details.

This WordPress message means PHP is running but couldn’t connect to the MySQL or MariaDB database. Nothing on the site can load until it does.

1. Check the credentials in wp-config.php

Open wp-config.php in the WordPress root folder and compare these four values with the database in cPanel’s MySQL Databases:

define('DB_NAME', 'account_wpdb');
define('DB_USER', 'account_wpuser');
define('DB_PASSWORD', '…');
define('DB_HOST', 'localhost');
  • On cPanel, database and user names are prefixed with your account name.
  • If you’re unsure of the password, set a new one for the user in MySQL Databases and paste it into wp-config.php.
  • DB_HOST is localhost on most shared hosting.

2. Check the user has privileges

In MySQL Databases, under Current Databases, confirm the user is listed against the database. If not, add the user to the database with All Privileges.

3. Check the database server is running

If other sites on the same server also fail, the database server may be down or overloaded. On a VPS:

sudo systemctl status mariadb   # or mysql

On shared hosting, contact support.

4. Repair corrupted tables

If the front end fails but /wp-admin shows a repair message, add this line to wp-config.php, visit /wp-admin/maint/repair.php, then remove the line:

define('WP_ALLOW_REPAIR', true);

5. After a migration

When you move a site, the database name, user and password usually change. Update wp-config.php with the new values and make sure you imported the database.

شارك X LinkedIn Facebook

الدخول إلى حسابك

أدِر نطاقاتك واستضافتك وفواتيرك من مكان واحد.

اتصال آمن مباشرة مع منطقة العملاء في ZSOLNET.

افتح لوحة تحكم ZSOLNET

ليس لديك حساب؟