Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Thu Feb 22, 2018 7:43 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Thu Feb 08, 2018 7:28 pm 
Offline

Joined: Thu Feb 08, 2018 7:16 pm
Posts: 5
ENV: Linux Mint, 18.2, php 5.6/7.0 mysql Ver 14.14 Distrib 5.7.21, for Linux (x86_64) using EditLine wrapper

Greetings all. I have installed Cacti in the above environment but am unable to generate any graphs. After some debugging I find that poller.php is unable to populate the db, giving the error: FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php'. I have tried the following steps:

1. Verified grants/permissions of the cacti user in mysql by connecting using those credentials on cli.
2. Double checked the settings in config.php are correct.
3. Changed the driver from mysqli to mysql to verify the mysqli driver is being used (abo_mysql.inc.php actually doesn't exist)
4. Verified all permissions on the directories are set to www-data/www-data

I searched for this problem in previous posts, but didn't find any exactly like it. Any ideas? Thanks in advance for looking.


Top
 Profile  
 
 Post subject: Re: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Thu Feb 08, 2018 8:24 pm 
Offline
Cacti User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 463
Are you seeing any PHP errors in the log files or any other warnings?

_________________
Cacti Resources:
Cacti Website
Cacti Issues
Cacti Releases

My resources:
How to submit Pull Requests
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
 Post subject: Re: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Fri Feb 09, 2018 6:27 am 
Offline

Joined: Thu Feb 08, 2018 7:16 pm
Posts: 5
No php errors, or any errors in /var/log/cacti/cacti, poller-error or rrd.log. The rest of the site works as expected.


Top
 Profile  
 
 Post subject: Re: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Fri Feb 09, 2018 8:27 am 
Offline
Cacti Guru User
User avatar

Joined: Thu Jan 31, 2008 6:39 am
Posts: 2664
Location: Kressbronn, Germany
PHP errors need to be enabled first, so go to your php.ini file and enable it by uncommenting

Code:
# error_log = syslog


to

Code:
error_log = syslog


Then restart the webserver and check your syslog for PHP errors.

Also check if se-linux is enabled which may prevent the Webserver to actually start any network connections ( to your database server )

_________________
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusTransporter | CereusReporting | nmidWebService | nmidSmokeping | nmidWeb2 |

Code:
CereusServer Master:  SYSTEM STATS: Time:2.5621 Method:spine Processes:1 Threads:16 Hosts:446 HostsPerProcess:446 DataSources:14683 RRDsProcessed:7573
CereusServer Agent:   SYSTEM STATS: Time:27.4840 Method:spine Processes:1 Threads:8 Hosts:16 HostsPerProcess:16 DataSources:114576 RRDsProcessed:48061


Top
 Profile  
 
 Post subject: Re: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Tue Feb 13, 2018 3:44 am 
Offline

Joined: Thu Feb 08, 2018 7:16 pm
Posts: 5
Thank you, I had already done that, and, no errors.


Top
 Profile  
 
 Post subject: Re: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Tue Feb 13, 2018 10:17 am 
Offline

Joined: Thu Feb 08, 2018 7:16 pm
Posts: 5
I installed from source, and got this: php poller.php
PHP Fatal error: Uncaught Error: Undefined class constant 'MYSQL_ATTR_FOUND_ROWS' in /usr/share/cacti/site/lib/database.php:53
Stack trace:
#0 /usr/share/cacti/site/include/global.php(215): db_connect_real('localhost', 'cacti', 'xxxxxxxx', 'cacti', 'mysql', '3306', false)
#1 /usr/share/cacti/site/poller.php(64): include('/usr/share/cact...')
#2 {main}
thrown in /usr/share/cacti/site/lib/database.php on line 53

php-cli: php --version
PHP 7.0.27-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jan 5 2018 14:12:46) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.27-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans


Top
 Profile  
 
 Post subject: Re: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Tue Feb 13, 2018 10:23 am 
Offline

Joined: Thu Feb 08, 2018 7:16 pm
Posts: 5
Having said that, doing:

Code:
php5.6 poller.php


and updating /etc/crontab with php5.6 seems to have solved this issue.


Top
 Profile  
 
 Post subject: Re: FATAL: Cannot connect to MySQL server on 'localhost'
PostPosted: Thu Feb 15, 2018 4:54 am 
Offline
Cacti User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 463
I would check if you have any differences between what the mods and settings are for both php5.6 and php7.0. Any differences may be causing the issue. You may also want to check the differences between apache and cli too if only cli is giving you the issues.

_________________
Cacti Resources:
Cacti Website
Cacti Issues
Cacti Releases

My resources:
How to submit Pull Requests
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group