Cacti Error – FATAL: Cannot connect to MySQL server

Some times we get following error while trying to connect to Cacti server using browser.



FATAL: Cannot connect to MySQL server on ‘localhost’. Please make sure you have specified a valid MySQL database name in ‘include/config.php’

You have to check few things step by step to resolve this.

1.      First check config.php file have correct detail of user and password of cacti user in database.

This will look like:

/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cactipassword";
$database_port = "3306";
$database_ssl = false;

2.      Second check error in apache logs:

If you are getting something error like:

PHP Warning:  include(): Failed opening ‘/usr/share/cacti/include/config.php’ for inclusion (include_path=’.:/usr/share/pear:/usr/share/php’) in /usr/share/cacti/include/global.php on line


Change permission to 644 of db.php file in “/etc/cacti” folder.

# chmod 644 /etc/cacti/db.php

Then try to access Cacti from browser:


Please follow and like us:

Written by 

Sachin Kumar is an IT professional, having a good experience of Linux, Windows, Oracle, Informix, Asterisk and VoIP. Email:


  • anonymous

    Hi Sachin,

    Been troubleshooting for 2 hours.

    This did the trick!

    Thank you very much.

Enjoy this blog? Please spread the word :)