[FATAL] DB Error: connect failed

Hi,
I have had this particular FreePBX VM running since Nov. 2012. Since Sunday Jan 12, 2014, the system is sending 3 emails from running cron failures. The content of the 3 emails are the same. The difference is the user being root and asterisk.

Today I have tried upgrading from 4.211.64-7 to 4.211.64-10
using the upgrade FreePBX upgrade scripts. However, the server (and this is happening to about 10 different FreePBX VMs) is still sending these emails.

The content of the emails are:

Subject: Cron root@sip21-tor /var/lib/asterisk/bin/freepbx-cron-scheduler.php
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Message-Id: [email protected]
Date: Mon, 13 Jan 2014 09:12:01 -0500 (EST)

[FATAL] DB Error: connect failed

Trace Back:

/var/www/html/admin/libraries/db_connect.php:63 die_freepbx()
[0]: DB Error: connect failed

/var/www/html/admin/bootstrap.php:98 require_once()
[0]: /var/www/html/admin/libraries/db_connect.php

/etc/freepbx.conf:9 require_once()
[0]: /var/www/html/admin/bootstrap.php

/var/lib/asterisk/bin/freepbx-cron-scheduler.php:5 include_once()
[0]: /etc/freepbx.conf

Subject: Cron asterisk@sip21-tor /var/lib/asterisk/bin/freepbx-cron-scheduler.php
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/var/lib/asterisk>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=asterisk>
X-Cron-Env: <USER=asterisk>
Message-Id: [email protected]
Date: Mon, 13 Jan 2014 09:21:01 -0500 (EST)

[FATAL] DB Error: connect failed

Trace Back:

/var/www/html/admin/libraries/db_connect.php:63 die_freepbx()
[0]: DB Error: connect failed

/var/www/html/admin/bootstrap.php:98 require_once()
[0]: /var/www/html/admin/libraries/db_connect.php

/etc/freepbx.conf:9 require_once()
[0]: /var/www/html/admin/bootstrap.php

/var/lib/asterisk/bin/freepbx-cron-scheduler.php:5 include_once()
[0]: /etc/freepbx.conf

I am able to connect to the MySQL db as root (without passwd) and as freepbxuser with passwd using the password from /etc/freepbx.conf. Able to select databases and select * from tables within those databases as either user.

If you happen to know the fix to this, I am much obliged.

Thank you in advance for your time and help.

I get the same error in that upgrade cycle. Did you ever find a solution?

Had the same type of error in upgrading from 4.211 to 5.211 using the upgrade script

I didnt have any of the cron errors, the errors popped after the update.

This fixed it up…

service mysqld stop
mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bak
service mysqld start

Thanks. This quick fix worked for me every time and saved me tons of grief.
I hade a couple of power outages causing the machine to go down dirty. This messes up the SQL db, which causes this error.
Any idea why this happens?

Newer versions of the FreePBX Distro have a mechanism in place to fix this

I installed the latest version earlier this year and have been applying all the update. I am on :
PBX Firmware: 5.211.65-6
PBX Service Pack: 1.0.0.0
I just need to stop this from happening every time the box powers off unexpectedly.
Any ideas of what I can do to avoid this issue.
Thanks.

Hiya riad63, did you manage to get this resolved? Its happening for us we are on 5.211.65-1. I also need to stop this happening ASAP.

service mysqld stop
mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bak
service mysqld start

is the manual fix

yum install mysql-init-fixer

will this fix the problem from happening again?
This problem happens whenever the machine shuts down from a power outage or power cord unplug. I just need to know if this fix, “yum install MySQL-init-fixer”, is a temporary solution, or is this a permanent solution to the problem. Thanks.

If you have a lot of plug pulls you need to have some training time because this hoses more than mysql. On a properly working system there is generally no reason to EVER do this.

If you have power outages often you should have a UPS rated to handle the system til the power can come back or until the system can go through a proper shutdown.

I was installing my new APC UPS when I accidentally powered off the machine. The question here is, is this a BUG or a feature.

Sorry to take so long to reply back.

What I do remember is, there was mysql.sock in /var/lib/mysql and once it is either moved or rm -f’d, one can start mysql (#service mysqld start).

I know others have already posted this answer here and they deserve the credit.

Hopefully, as one person posted, a fix to prevent mysql.sock from hanging around will be in a new release or update in the near future.

You also need to be sure there is no /var/run/mysqld/mysqld.pid if you have an abrupt power failure. If you do have an abrupt power failure, pray there was nothing being written to the disks at the time of power loss [or hitting the reset button] (if you don’t use a good RAID Controller WITH Battery Backup…). If you do experience a power failure, I would recommend to you to boot into single user mode and run #fsck -y to be sure you don’t have any inodes messed up and your file system(s) are pristine.

Cheers.

A server pooping itself with a sudden loss of power is expected behavior. It is not a bug or a feature.

If I set your house on fire is “flammability” a bug or a feature? The answer is don’t do that.

Don’t forget that FreePBX is a Linux based server. Unplugging any server is bad. If you doubt me and work ina Microsoft environment stop by your data center and unplug a Windows server, especially one running MSSQL and see what happens.

So I have the same question. Is this a fix for the issue? I understand that no one should just power off a server etc. But things do happen and there are consequences for that not so intelligent decision. I have had this happen as well. Complete accident when it happened.

Yes. It is the fix. That’s that

[FATAL] DB Error: connect failed

Hello freepbx users,

I just had this problem too. The system has run fine for years and then recently I started seeing this error in failed cron jobs and when I tried to log in to the GUI.

I traced the problem to a “too many connections” error from our MySQL database. I increased the maximum to 250, restarted mysqld, and have had no problems since.

You can set this parameter in the /etc/my.cnf file. In the “[mysqld]” section add the line:

set-variable=max_connections=250

Hope this is of help to others.

bkelly

hi, i’m having this same problem, i tried your solutions but it doesn’t work for me, i get this error?

rm: cannot remove `/var/lib/mysql/mysqld.sock ': No such file or directory

I’m pretty sure that nothing in this thread will work for that problem - the original problem was over seven years ago.

You need to (if you haven’t already) start your own thread with FreePBX Version, whether it is a Distro install or not, and what you’re trying to do.