AdminsForum

CyberPanel Databases & phpMyAdmin Guides

Guide Change MySQL Passwords on CyberPanel Without Breaking phpMyAdmin or Your Site

Started by JAY 0 replies 126 views
1JAY
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
#1
Change MySQL Passwords on CyberPanel Without Breaking phpMyAdmin or Your Site (Tested)

Two password changes cause a lot of trouble on CyberPanel servers: changing the MySQL root password (afterwards phpMyAdmin won't open and you can't create databases), and changing a website's database password (the site shows "Error establishing a database connection"). We did both on purpose on a CyberPanel 3.0.8 server (Ubuntu 24.04, MariaDB 10.11), watched what broke, and fixed it. Here's what to change, and where.

Part 1: A website's database password
In the panel this lives under Databases → List Databases. Pick the website and use the Change button next to the database:
cyberpanel list databases change password   
The panel changes the password in MariaDB. It does not know your website's config file, so the site keeps using the old one. We tested the same thing over SSH. Right after the password change, our WordPress site answered:
Code:
500 Error establishing a database connection
The fix is to put the new password into the site's config. For WordPress, WP-CLI does it in one line (run it as the website's user, see
Code:
stat -c %U
on the file to find it):
Code:
cd /home/yourdomain.com/public_html sudo -u SITEUSER wp config set DB_PASSWORD 'your-new-password'
It answered Success: Updated the constant 'DB_PASSWORD'. Two things we noticed:
  • WP-CLI prints the new password on screen in that success line. Clear your terminal if someone can see it.
  • Wait a few seconds before you test. We checked the site in the same second and still got the error. A moment later it was back to
    Code:
    200
    . PHP keeps a copy of your files in memory and only re-reads them every 2 seconds on our server (
    Code:
    opcache.revalidate_freq = 2
    ).
For other apps, edit the password in their config file by hand (
Code:
.env
for Laravel,
Code:
configuration.php
for Joomla, and so on).

Part 2: The MySQL root password
CyberPanel itself logs in to MariaDB as root to create databases and to open phpMyAdmin for you. It reads that password from its own files. If you change the password only in MariaDB, the panel is left with the old one.

What broke on our server after changing only the root password:
  • Create Database failed with: Database creation stopped at checking_sql_namespace ... Ask the administrator to check the CyberPanel error log.
  • phpMyAdmin didn't open. Clicking it just dropped us back on the dashboard, with no error message.
  • The panel's log (
    Code:
    /home/cyberpanel/error-logs.txt
    ) showed the real reason: Access denied for user 'root'@'localhost' (using password: YES).
  • Commands that rely on the saved password stopped working too (
    Code:
    mysql
    as root without typing a password).
What kept working: all websites, email, DNS and the list of existing databases. Those don't use the root login.

The three places to update. Back them up first:
Code:
mkdir -p /root/rootpw-backup cp -a /etc/cyberpanel/mysqlPassword /root/.my.cnf /usr/local/CyberCP/CyberCP/settings.py /root/rootpw-backup/
Change the password in MariaDB (if you haven't yet):
Code:
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'your-new-password'; FLUSH PRIVILEGES;"
Then put the same new password in:
  1. Code:
    /etc/cyberpanel/mysqlPassword
    : the file contains only the password.
  2. Code:
    /root/.my.cnf
    : the password line.
  3. Code:
    /usr/local/CyberCP/CyberCP/settings.py
    : near the end there's a
    Code:
    DATABASES
    section with two blocks. Change the
    Code:
    'PASSWORD'
    in the second block, the one named
    Code:
    'rootdb'
    with
    Code:
    'USER': 'root'
    .
Restart the panel's own service:
Code:
systemctl restart lscpd
After that, on our server:
Code:
mysql
logged in as root again, Create Database worked (the same request that had failed now returned success), and phpMyAdmin opened normally.

The trap in settings.py
On a fresh install, the first block in that DATABASES section (user
Code:
cyberpanel
) has the same password as root. We checked: the original root password also logged in as the
Code:
cyberpanel
database user. So if you search and replace the old password everywhere in
Code:
settings.py
, you also change the first block, and then the whole panel can't reach its own database.

Change only the
Code:
rootdb
block. Leave the
Code:
cyberpanel
user's password alone unless you have a strong reason: on our server that same password was also stored in the config files of Postfix, Dovecot, PowerDNS and Pure-FTPd (
Code:
/etc/postfix/mysql-virtual_*.cf
,
Code:
/etc/dovecot/dovecot-sql.conf.ext
,
Code:
/etc/powerdns/pdns.conf
,
Code:
/etc/pure-ftpd/
). Changing it means updating all of them, or mail, DNS and FTP stop. We didn't change it.

phpMyAdmin won't open? Check this first
If phpMyAdmin bounces you back to the dashboard, or database creation fails, test whether the panel's saved root password still works:
Code:
mysql -uroot -p"$(cat /etc/cyberpanel/mysqlPassword)" -e "SELECT 1;"
Access denied means the saved password is out of date, and Part 2 is your fix. If it prints
Code:
1
, the password is fine and the cause is something else. Look at the last lines of
Code:
/home/cyberpanel/error-logs.txt
right after you click.

Questions, or a different error after a password change? Reply below with the last lines of that log (hide passwords and your server IP).
Reply
Possibly Related Threads…matched by title
Replies:0Views:161
Replies:0Views:121
Replies:0Views:197
Replies:0Views:190
Replies:0Views:240

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