FATAL ERROR DB Error: connect failed

My FreePBX on a VPS has been running for quite some time already.

Just recently I tried maximizing my VPS by adding some virtual hosts (multiple domains in 1 VPS).

I had also removed (via Webmin) all anonymous/no_password mysql users as my server was compromised (i.e. someone added an unauthorized route).

I don’t know which caused the problem but when I tried logging in on the FreePBX Administration link am getting this error.

FATAL ERROR
DB Error: connect failed

Both Voicemail & Recordings (ARI and Flash Operator Panel (FOP)links are still working.

Already remove the virtual host…

Also, I can still register to my SIP extensions and can do outgoing calls…
I need the login to work for me to administer (e.g add extensions, users, trunks, routes, etc).

Hoping for some guide/help in resolving the issue.

Thanks.

Voicemail & Recordings (ARI) is also not working… below is the complete error msg.

DB Error: connect failed

Cannot connect to the asterisk database
Check AMP installation, asterisk, and ARI main.conf

Hi

Need to know your FreePBX version.

Try,

netstat -an | grep 3306

You should see something listed, meaning MySQL is alive and running.

Normally, a good place to check your DB passwords are in

/etc/amportal.conf (or /etc/freepbx.conf for newer versions), look for

AMPDBNAME=asterisk
AMPDBENGINE=mysql
AMPDBHOST=localhost
AMPDBUSER=???
AMPDBPASS=???

Then, using those creds in that file, try to

mysql -u asteriskuser -p

       ^-normally the asterisk user to connect to DB is asteriskuser, but that can be different depending on what you saw in amportal.conf that says

If you can connect, try executing…

mysql> use asterisk;
mysql> select * from ampusers

If you’ve come this far without any issues, then your DB connection information is OK and its something else.

Let us know how far you’ve come… :slight_smile: good luck

On another note, to begin, DO NOT ALLOW public access to your

  1. HTTP(freepbx interface)
  2. AMI
  3. DB (Sql tcp ports)

Use VPNs, if you can. Otherwise, best do SSH tunneling (thus opening/allowing only SSH into your servers to use those above ports/services)

Hi sanjayws,

Thanks for replying.

I’m using FreePBX 2.7.0.0

Here’s what I got from my amportal.conf

AMPDBNAME=asterisk
AMPDBENGINE=mysql1
AMPDBHOST=localhost
AMPDBUSER=freepbx
AMPDBPASS=fpbx

Changing back the default account freepbx/pbx (user/password) seems to did the trick. I can already login to the http interface w/o any error.

(Perhaps this is the same account used to hack into my server.)

Question left now is, how can I change the default freepbx/fpbx account w/o getting the same error? It can’t be modified by the passwd command?

Will try to change manually in the amportal.conf, hopefully it won’t cause any error though (previous change was made via Webmin).

On security:
I already tried limiting access to my server by only allowing specific IP ranges for Webmin & SHH… but I dunno how to limit access to http freepbx interface and all others-- although, entering the server’s IP address will now route to my other website. Entering the domain will still get the http interface.

Hi buddy, try googling

“how to change freepbx passwords”

All your answers are first top hits…

As for limiting access, try using IPTABLES, builtin firewall on *Nix systems. Its simple to use and pretty much does what it says it does…

You could for example, only allow SSH from anywhere but limit others to only internal networks.

Good luck!

thanks, sanjayws.

the problem is when i tried changing the password… it leads right back to the original error in the 1st post.

FATAL ERROR
DB Error: connect failed

tried changing via the amportal.conf manually and also tried via SQL by using the commands below:

mysql -u username -p
SET PASSWORD FOR asteriskuser@localhost=PASSWORD(‘newpass’);

i had to set it back to the original password to connect.

any other way of changing it correctly?

You have the dbusername as freepbx not asteriskuser.

You have to do an amportal restart after changing amportal.conf

SET PASSWORD FOR freepbx@localhost=PASSWORD(‘newpass’);

(the one posted above was just for presentation purposes).

I restarted amportal after changing amportal.conf but still getting same error and is only resolved if the original password is returned.

**actually got this error after restarting amportal and then returning the original password.

Not Found

The requested URL /admin/ was not found on this server.

resolved only when i did “service asterisk restart”.

it seems changing the default freepbx default password will cause errors.

Are the variables redeclared later in amportal.conf?

You can change the credentials without issue.

got it from this post
http://forums.asterisk.org/viewtopic.php?f=14&t=74423

here’s the exact procedure copied…

  • from a command prompt as root run the command “mysql” without the quotes. Depending on if you’ve overridden the username/password combination you might need to pass switches “mysql –u root –p” or some combination to login.
  • once inside the mysql prompt run the SQL statement “use mysql”
  • then run the SQL statement “UPDATE user set Password=PASSWORD(‘newsecretpassword’) WHERE User=’freepbx’
  • then run the SQL statement “flush privileges”
  • exit the mysql prompt
  • use a text editor to open /etc/amportal.conf
  • find the AMPDBPASS line and change the value fpbx to your newsecretpassword that you set earlier in MySQL
  • text editor next on /etc/asterisk/cdr_mysql.conf
  • find the fpbx password value and replace the old password with your newsecretpassword
  • text editor next on /etc/asterisk/extensions_additional.conf (I know you shouldn’t edit this directly but you need to since you can’t “Apply Changes” to regenerate this file yet)
  • find the fpbx password value and replace the old password with your newsecretpassword
  • now that you’ve changed these files execute a amportal restart command and you should be good to go

everything seems normal now…

thanks everyone.

hi…
someone please help me i have same problem
i has tried command # /etc/amportal.conf
then i got this>> -bash: /etc/amportal.conf: Permission denied
what happen with our FreePBX??

Working fine on Friday. Didn’t change anything.
Then Monday morning, I tried to use admin gui and failed.
Server says mysql is not running.
Hope I have better luck with a response than he did.

Try and restart MySQL.

We could offer more details if we knew what Distro and Version of things you are running.

Got most recent stable version of FreePBX (Stable-5.211.65-5) mostly set up yesterday. Shut down machine overnight and planned on finishing set up today, but after starting up this morning I’m receiving this when trying to login to GUI:

FATAL ERROR 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/www/html/admin/config.php:109 include_once()
[0]: /etc/freepbx.conf

Contents of freepbx.conf:

<?php $amp_conf['AMPDBUSER'] = 'freepbxuser'; $amp_conf['AMPDBPASS'] = 'wKQgN9mceydD'; $amp_conf['AMPDBHOST'] = 'localhost'; $amp_conf['AMPDBNAME'] = 'asterisk'; $amp_conf['AMPDBENGINE'] = 'mysql'; $amp_conf['datasource'] = ''; //for sqlite3

require_once(’/var/www/html/admin/bootstrap.php’);

Tried restarting mysqld service. Here’s what I get:

[root@localhost etc]# service mysqld restart Stopping mysqld: [ OK ] Another MySQL daemon already running with the same unix socket. Starting mysqld: [FAILED]

Tried stopping mysqld and starting as separate operations, same problem.

No login attempts to mysql from the command line succeed. I get…

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

When I try to nano mysql.sock I get…

Error reading mysql.sock: No such device or address

This is a default installation. I’ve only worked through the GUI so far. The install is fresh, there’s plenty of space both in RAM and on the hard disk. Every suggestion I’ve looked up advises going into mysql to try this or that, but I can’t get in. MySQL appears to be running; I appear to be able to stop it successfully; but whenever I try to start it, it says it’s already running.

I’m stumped. Have things somehow corrupted on day 2? Any advice would be much appreciated.

Thanks,

Doug

The Stable-5.211.65-5 is the FreePBX distro version. I chose version 11 of Asterisk on install.

Solved the problem by renaming the mysql.sock file and then restarting both the mysqld service and the asterisk service. I was in a hurry to shutdown the machine last night and just powered it off rather than shutting it down smoothly. That this tanked the pbx makes me nervous. I’m in a rural area and we have power outages semi-regularly. Is this normal behavior? No other linux distro I’ve worked with gets so messed up by a simple loss of power. Anything to do about it? I’ll not always be around to clean up after an outage.

yum install mysql-init-fixer

Thanks! Perfect!

I have the same issue, which I solved with following:
service mysqld stop
mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bak
service mysqld start
service asterisk restart

The problem is that if I shutdown the server and restart, I have to do this again! I had this issue twice, in both times Freebbx was working fine, and then I got a bunch of errors on the centos console. The firs time I rebuilt the system from scratch and restored backup. When it happen again after a few days working… I used the above. Both times I built from an USB Key on my netbook.

Any clue why it happens when I reboot?

Thanks!

There is a bug in the variant of CentOS we use that doesnt shutdown mysql correctly leaving the socket file behind, when mysql starts it sees the socket file and thinks that it’s already running so aborts.

If you run: yum install mysql-init-fixer

It removes the socket file on startup to avoid this issue.