AdminsForum

CyberPanel WordPress & LSCache Guides

Guide Fix "Error Establishing a Database Connection" in WordPress on CyberPanel

Started by JAY 0 replies 92 views
1JAY
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
#1
Fix "Error Establishing a Database Connection" in WordPress on CyberPanel

The page is white with one sentence: Error establishing a database connection. WordPress shows the same message for half a dozen different problems, so guessing wastes time. We broke a test WordPress site on CyberPanel (3.0, OpenLiteSpeed, MariaDB 10.11) on purpose, in every common way, and noted the exact error behind each one. With one command you can see which one you have.

Step 1: Get the real error
Log in with SSH and go to the site's folder (the one with
Code:
wp-config.php
). Run WP-CLI as the website's user (find it with
Code:
grep extUser /usr/local/lsws/conf/vhosts/DOMAIN/vhost.conf
):
Code:
cd /home/example.com/public_html sudo -u SITEUSER -H wp db query "SELECT 1" --skip-plugins --skip-themes
It uses the same settings as the website, but prints the real database error:
WordPress hides the reason, WP-CLI tells you:
[Image: attachment.php?aid=627]

Here:
Code:
ERROR 1045 ... Access denied for user 'moved_wp'@'localhost' (using password: YES)
, a wrong password. Find your error in the list below. To see what the site uses:
Code:
sudo -u SITEUSER -H wp config get DB_NAME sudo -u SITEUSER -H wp config get DB_USER sudo -u SITEUSER -H wp config get DB_HOST

Watch out, the homepage can look fine. With LiteSpeed Cache, the homepage still loaded from the cache (
Code:
x-litespeed-cache: hit
, status 200) while
Code:
wp-login.php
and every page not in the cache showed the error. So test
Code:
/wp-login.php
, not only the homepage:
Homepage fine, login page broken:
[Image: attachment.php?aid=629]


ERROR 1045: Access denied ... (using password: YES)
The password in
Code:
wp-config.php
doesn't match the database user's. On CyberPanel the usual reason: someone changed it in Databases > List Databases > Change. That changes the password in MariaDB only;
Code:
wp-config.php
still has the old one. We changed the user's password directly in MariaDB, which is what that button does, and got exactly this error. Fix: put the current password in
Code:
wp-config.php
:
Code:
sudo -u SITEUSER -H wp config set DB_PASSWORD 'THE-PASSWORD' --quiet
Don't know it? Set a new one in List Databases > Change, then the same command. Right after that our test query answered
Code:
1
and the login page loaded again (screenshot below).

ERROR 2002: Can't connect to local server through socket
MariaDB isn't running, so every site on the server that uses a database is down at once. We stopped MariaDB for this test:
Password fixed, then MariaDB stopped:
[Image: attachment.php?aid=630]

Code:
systemctl start mariadb systemctl status mariadb
Then find out why it stopped, or it will happen again:
Code:
journalctl -u mariadb -n 50 dmesg -T | grep -iE 'out of memory|killed process'
On small VPSes the most common reason is RAM: the kernel kills the biggest process (MariaDB) when memory runs out. Add swap or more RAM, or lower MariaDB's
Code:
innodb_buffer_pool_size
. A full disk (
Code:
df -h
) also stops MariaDB.

ERROR 1044: Access denied for user ... to database '...'
The user and password are right, but
Code:
DB_NAME
is wrong, or this user has no rights on that database. Common after a migration, when the database got a different name on the new server. Check the exact names in Databases > List Databases and set the right one:
Code:
sudo -u SITEUSER -H wp config set DB_NAME the_real_name

ERROR 2005: Unknown server host '...'
Code:
DB_HOST
still has the old host's database server (some hosts use names like
Code:
mysql.example.com
or an internal IP). On CyberPanel the database runs on the same server:
Code:
sudo -u SITEUSER -H wp config set DB_HOST localhost
Both errors in our test:
Wrong database name, then a wrong host:
[Image: attachment.php?aid=631]

Code:
localhost
is right for CyberPanel (
Code:
localhost:3306
, which our older site used, works too). CyberPanel creates every database user for both
Code:
localhost
and
Code:
127.0.0.1
.

Still broken?
  • Query works in WP-CLI, website still shows the error: purge the cache (
    Code:
    sudo -u SITEUSER -H wp litespeed-purge all
    ) and test again. Also check for a second
    Code:
    wp-config.php
    one folder above
    Code:
    public_html
    ; WordPress reads that one if the first is missing.
  • "Too many connections": a plugin or a bot flood uses up all connections; check with
    Code:
    mysqladmin -u root -p processlist
    .
  • "Table ... is marked as crashed" (MyISAM after a crash):
    Code:
    sudo -u SITEUSER -H wp db repair
    .

Quick reference
  • 1045, access denied (using password: YES): wrong password, set
    Code:
    DB_PASSWORD
    .
  • 2002, can't connect through socket: MariaDB down, start it and find out why.
  • 1044, access denied to database: wrong
    Code:
    DB_NAME
    or no rights.
  • 2005, unknown server host: wrong
    Code:
    DB_HOST
    , use
    Code:
    localhost
    .

More CyberPanel guides Tested on CyberPanel 3.0 with OpenLiteSpeed, MariaDB 10.11 and WordPress 7.1 with LiteSpeed Cache on Ubuntu 24.04, October 2026. All errors were caused on purpose on a test site and fixed afterwards.

Attached Files

Image(s)
               
Reply
Possibly Related Threads…matched by title
Replies:0Views:10
Replies:0Views:124

Users browsing this thread: 1 Guest(s)
Forum Jump: