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

1)、查看config.php下,是否配置正确
查看cactiusr的host是否有localhost 权限
mysql -ucactiuser -h localhost -p
查看登录是否成功 ,如果登录正常则排除
2)、MYSQL权限问题
SQL>GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'somepassword';
3)、当mysql中的所有配置和cacti的config.php都正确,却还是出现该错误时,那就是mysql套接字的原因了~
cacti会自动的去查找/var/lib/mysql/mysql.sock 该套接字,但是如果是源码安装的mysql,未指定套接字位置时,套接字的位置为/tmp/mysql.sock,由于cacti未找到/var/lib/mysql/mysql.sock,所以显示的是“Cannot connect to MySQL server on 'localhost'”

解决:做一个/tmp/mysql.sock到/var/lib/mysql/mysql.sock的软连接
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock