DB Error: unknown error

Hi all,
Centos 5.4
Repo: asterisk-current
FreePBX Version: 2.7.0
Asterisk18 Version : 1.8.6.0

So it didn’t break itself… I installed vTigerCRM which installed a new database in mysql but didn’t affect the asterisk database or freepbx:fpbx login. I did however stuff the permissions in /var/www/html/*. I recovered all the folders/files in html from good backups and restored ownership of the freepbx folders to asterisk:asterisk.

So I get the error : “DB Error: unknown error” and emails with “[FATAL] database connection failure failed trying to connect to the configured database”

I’ve run “mysqlcheck -r asterisk” and everything reports back “OK”.

Any ideas? I thought reinstalling everything again was in order (I am loathed to do that, this is not a windows box far out) but reinstalling asterisk and freepbx from scratch is a PITA. So damned complex black magic.

Thanks for any help.

OK, what about backing up the asterisk DB, removing it and importing a fresh/blank copy? Not sure where I would get that from?

Can you connect to the database with the credentials that FreePBX knows? (In other words, the username and password FreePBX would use to connect.) In FreePBX 2.7, these are in the /etc/amportal.conf file as AMPDBUSER and AMPDBPASS.

Type “mysql -u USERNAME -p PASSWORD asterisk”

change the USERNAME and PASSWORD to the right ones of course.

Does it connect?

If not, is MySQL running? (ps ax | grep mysqld)

Is it listening? (netstat -an | grep LISTEN | grep 3306) You should see a line for 0.0.0.0:3306 LISTEN or maybe 127.0.0.1:3306 LISTEN.

Any interesting errors in the web server’s error_log?

Hello, thanks for the reply.
I should have been more specific in the first post but yes MYSQL is running and yes can connect to database asterisk with username and password (AMPDBUSER=freepbx, AMPDBPASS=fpbx) as per the default install.
As for /var/log/httpd/error_log , no nothing interesting really. Everytime I try and access http://192.168.64.2/admin/ I get the fabled:

[Thu Sep 15 18:35:34 2011] [error] [client 192.168.64.2] File does not exist: /var/www/html/favicon.ico

… which is irrelevant.

This still isn’t resolved. The system is emailing be about the DB error every hour. Hour after hour…
There’s obviously a corruption of the DB. Can anyone suggest some steps to create a new database?

The freepbx-cron-scheduler.php file is the one generating the alerts/e-mails to you.

It just does a database connectivity test. So it’s got to be a permissions issue.

This is the code that runs:

       case "mysql":
                /* datasource in in this style:
                dbengine://username:password@host/database */
                
                $db_user = $amp_conf["AMPDBUSER"];
                $db_pass = $amp_conf["AMPDBPASS"];
                $db_host = $amp_conf["AMPDBHOST"];
                $db_name = $amp_conf["AMPDBNAME"];
                
                $datasource = $db_engine.'://'.$db_user.':'.$db_pass.'@'.$db_host.'/'.$db_name;
                $db = DB::connect($datasource); // attempt connection
                break;

As you can see it seems to do nothing except attempt connection. Then if that doesn’t work this is the notice you get:

if(DB::isError($db)) {
        out(_("FAILED"));
        debug($db->userinfo);
        fatal(_("database connection failure"),("failed trying to connect to the configured database"));

Why don’t you try resetting privileges using commands like this (start with ‘mysql -u root’ or ‘mysql -u root -p’ and type the mysql root password):

mysql> grant all privileges on asteriskcdrdb.* to USERNAME@localhost identified by ‘PASSWORD’;
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on asterisk.* to USERNAME@localhost identified by ‘PASSWORD’;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

(change USERNAME and PASSWORD to the right ones of course)

Thanks again billsimon.

I ran the resetting privileges command you suggested - they ran fine without error. Restarted amportal, restarted httpd - same error, no progress.

Looking at that code snippet you showed me, I can verify this:

  • Configuration file is /etc/amportal.conf. It is untouched by me from initial install and includes the following to prove the values are actually there.
    AMPDBHOST=localhost
    AMPDBUSER=freepbx
    AMPDBENGINE=mysql
    AMPDBPASS=fpbx
    AMPENGINE=asterisk
    AMPDBNAME=asterisk

I can run “mysql -u freepbx -p asterisk” with password “fpbx” and I get access to the database.

My asterisk runs fine, the web interface is obviously the issue. It urks me that something simple can render this interface unusable.

OK, I’ve uninstalled everything FreePBX but left Asterisk installed.
Can anyone tell me how to stop the emails being sent to me every hour??

How did you uninstall FreePBX? Sounds like the cron job is still running.

You could have just rerun the install_amp script.

My guess is that the db settings are declared again at the bottom of amportal.conf. Last declaration wins.

Uninstall FreePBX? Sure, “yum remove freepbx” worked here :slight_smile:
Are you saying I could have run the install_amp script and it would have re-initialised the freepbx install, database and all? Perhaps I should delete the asterisk DB from MYSQL then run the script (if it exists here)?
There are no duplicates in my amportal.conf. It was never changed since the initial install. Absolute default. Somehow the database has corrupt or something…
Still getting an email every hour. I see no cron jobs anywhere for it.

Gotta be a cron job. FreePBX does not produce an RPM, it is distributed as a tarball so I am not sure of where you got the RPM, maybe other distro’s repackage it.

What happens if you use the command line tool to access the database:

mysql -u username -p
supply password
use asterisk;
show tables;

Found it darn it. I had a brain fart and didn’t look under /var/spool/cron/. There’s an asterisk item there:

0 0 * * 0 /var/lib/asterisk/bin/ampbackup.php 1
5 * * * * /var/lib/asterisk/bin/freepbx-cron-scheduler.php

Should have just disabled that.

I’m in the process of removing all of asterisk and freepbx, databases, everything and reloading from scratch which I think is the ultimate cop out. I’ve been a Linux user since 1998 and it is rare I have been unable/unmotivated to work out why a package went mental. IMO, FreePBX is still poorly documented with the most bizzaar forum software/format I’ve ever seen. If I wasn’t so lazy I would go back to running asterisk from .conf files.

Regarding RPMs. I’m using the asterisk-current repo under Centos 5.7.

Check your PM

I had the same error in my centos 5.5