[Solved] Database connection error – RoundCube – cPanel

Encountered a database error for Webmail client RoundCube. The MySQL database connection problem can occur due to several reasons. Please check the following details and this will help you to troubleshoot the problem. The error details are pasted below:

DATABASE ERROR: CONNECTION FAILED!

Unable to connect to the database!
Please contact your server-administrator.

You’ve to check number of things for troubleshooting this. Please do follow the steps below:

round

ADMIN NOTE: THIS WAS TESTED UPTO VERSION 64.

1, Check your MySQL is running or not.

From the command-line you can follow the below pasted command:

/etc/init.d/mysql status

If it’s running the output should be like;

[root@vps ~]# /etc/init.d/mysql status
mysqld (pid  837) is running...

Okay, then we can move onto database and the user “roundcube”. The database and the user is “roundcube”. The password for the database user will be obtained from the file “/usr/local/cpanel/base/3rdparty/roundcube/config/db.inc.php” in a cPanel server.

# grep roundcube /usr/local/cpanel/base/3rdparty/roundcube/config/db.inc.php
$rcmail_config['db_dsnw'] = 'mysql://roundcube:YfxAEk31hEN0dhEF@localhost/roundcube';
// postgres example: 'pgsql://roundcube:pass@localhost/roundcubemail';

Or # grep roundcube /usr/local/cpanel/base/3rdparty/roundcube/config/config.inc.php

2, Check the database connectivity from command line

Yes, we need to verify whether the db user and password is working. Please use the following command:

# mysql -u roundcube -p

If you are able to get in, check the database is listing under the user.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| roundcube          |
+--------------------+
2 rows in set (0.09 sec)

If the user password is not working that’s reason for this db error. Please reset the user password.

3, Check the tables are existing under the database;

Switch to database “roundcube”;

mysql> use roundcube;

Check tables;

mysql> show tables;
+---------------------+
| Tables_in_roundcube |
+---------------------+
| cache               |
| cache_index         |
| cache_messages      |
| cache_thread        |
| contactgroupmembers |
| contactgroups       |
| contacts            |
| cp_schema_version   |
| dictionary          |
| identities          |
| searches            |
| session             |
| system              |
| users               |
+---------------------+
14 rows in set (0.00 sec)

If all tables exists then go ahead and repair the database. Please follow the command to repair a db.

# mysqlcheck -r roundcube

If database or tables are missing, you can rebuild the roundcube from commanline.

Shutdown your test infra and reduce cost – AWS

I hope this article should be helpful for you, if you are managing a medium or large size infra in AWS platform.

There should be a lot of services or instances that we can shutdown for many hours in a day. Consider your production infra contains 10 large type EC2 instances and your organisation have 2 QA and 1 test environment of exactly same number of instances and services like your running production infra.

Command to rebuild RoundCube:

/usr/local/cpanel/bin/update-roundcube --force

FYI, the force rebuild will results in missing of address book, signatures etc
Otherwise, if you have a backup you can try a restoration instead-of rebuild.

4, RoundCube batabase, user, tables and password all are working. But I have saved address book and others in email accounts, can I rebuild the roundcube safely?

If all working, please take a backup of database then drop it before rebuilding the roundcube.

4.1 Backing up db:

# mysqldump roundcube > roundcube.sql

4.2 Dropping db:

DROP DATABASE roundcube;

Run above command in MySQL prompt.

4.3 Rebuild

/usr/local/cpanel/bin/update-roundcube --force

4.4 Restore

# mysql roundcube < roundcube.sql

That’s it!

Admin note: I created this post some years ago (If I recollect correctly upto WHM 60), check the comment by Sambhu also for latest cPanel version.

Also read:

1, Is there any way to enable SPF and DKIM for all newly creating cPanel accounts by-default?
2, Unable to establish a PHP session – PHPMyAdmin error
3, How to change main domain of a cPanel reseller account with an existing domain name?

Post navigation

Arunlal A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

9 thoughts on “[Solved] Database connection error – RoundCube – cPanel

  1. Thanks u r article so much useful ..
    the default password is “password”
    just edit /path/to/roundcubehomedir/config/config.inc/php

    and change
    $config[‘db_dsnw’] = mysql://roundcube:password@localhost/roundcubemail’;

    Thanks.
    “O.O”

  2. ssh root

    cd /usr/local/apache/htdocs/roundcube/config/

    nano db.inc.php

    $rcmail_config[‘db_dsnw’] = ‘mysqli://roundcube:password@localhost/roundcube’;

    change

    $rcmail_config[‘db_dsnw’] = ‘mysql://roundcube:password@localhost/roundcube’;

    mysqli change mysql 🙂

  3. I noticed that my Android phone and Outlook were fine but I could not access RoundCube while Horde and SquirelMail was fine. Did a force and now it’s fine and think it’s time to switch away from RoundCube.

  4. root@mail:~# mysql> show tables;
    ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)

    HElp me pls i dont know what i have to do?

      1. I am not able to get mailbox login in ISPConfig.

        DATABASE ERROR: CONNECTION FAILED!
        Unable to connect to the database!
        Please contact your server-administrator.

        /var/log/roundcube/

        [12-Feb-2020 15:48:30 +1100]: DB Error: SQLSTATE[HY000] [1045] Access denied for user ’roundcube’@’localhost’ (using password: YES) in /usr/share/roundcube/program/lib/Roundcube/rcube_db.php on line 176 (GET /webmail/)
        [12-Feb-2020 15:48:30 +1100]: DB Error: SQLSTATE[HY000] [1045] Access denied for user ’roundcube’@’localhost’ (using password: YES)

Leave a Reply

Your email address will not be published. Required fields are marked *