"[FATAL] Cannot connect to database" while installing on Ubuntu 14.04

I’ve been following the wiki, but when I get to

 ./install_amp --installdb --username=asteriskuser --password=${ASTERISK_DB_PW}

I get an error:

    [email protected]:/usr/src/freepbx# ./install_amp --installdb --username=asteriskuser --password=${ASTERISK_DB_PW}
Checking for PEAR DB..OK
Checking for PEAR Console::Getopt..OK
Using username: asteriskuser
Using password: *****************
Checking user..OK
Checking if Asterisk is running..running with PID: 4622..OK
Checking for /etc/amportal.conf..OK
Reading /etc/amportal.conf..parsed amp_conf variables from /etc/amportal.conf:
amp_conf [AMPDBHOST] => [obsidian]
amp_conf [AMPDBENGINE] => [mysql]
amp_conf [AMPENGINE] => [asterisk]
amp_conf [AMPMGRUSER] => [admin]
amp_conf [AMPMGRPASS] => [mypass]
amp_conf [AMPBIN] => [/var/lib/asterisk/bin]
amp_conf [AMPSBIN] => [/usr/local/sbin]
amp_conf [AMPWEBROOT] => [/var/www/html]
amp_conf [AMPCGIBIN] => [/var/www/cgi-bin ]
amp_conf [FOPWEBROOT] => [/var/www/html/panel]
amp_conf [FOPPASSWORD] => [mypass]
amp_conf [AUTHTYPE] => [database]
amp_conf [AMPEXTENSIONS] => [extensions]
amp_conf [AMPDBUSER] => [asteriskuser]
amp_conf [AMPDBPASS] => [mypass]
amp_conf [AMPWEBADDRESS] => [192.168.1.2]
amp_conf [AMPDBNAME] => [asterisk]
amp_conf [ASTETCDIR] => [/etc/asterisk]
amp_conf [ASTMODDIR] => [/usr/lib/asterisk/modules]
amp_conf [ASTVARLIBDIR] => [/var/lib/asterisk]
amp_conf [ASTAGIDIR] => [/var/lib/asterisk/agi-bin]
amp_conf [ASTSPOOLDIR] => [/var/spool/asterisk]
amp_conf [ASTRUNDIR] => [/var/run/asterisk]
amp_conf [ASTLOGDIR] => [/var/log/asterisk]
OK
Checking for /etc/asterisk/asterisk.conf..OK
Reading /etc/asterisk/asterisk.conf..OK
Using asterisk as PBX Engine
Checking for Asterisk version..12.8.0
Checking for selinux..OK
Connecting to database..FAILED
Try running ./install_amp --username=user --password=pass  (using your own user and pass)
[FATAL] Cannot connect to database
[email protected]:/usr/src/freepbx#

I’ve also run the command with the password from amportal.conf with no success. I’m really out of ideas here. I’ve been looking for a solution for hours straight.
I saw a post similar to this from October, but is a full reinstall really the only way to fix this?
Any help would be greatly appreciated.

What happens when youmysql -u asteriskuser -ppassword
Example with password being “nospaceafterdashp”

If not, while logged in as root, just type “mysql” and

USE mysql; UPDATE user SET Password='newpassword' WHERE User='asteriskuser'; flush privileges;

Alternatively, I’d try the whole sequence from the install guide:

cd /usr/src/freepbx
export ASTERISK_DB_PW=amp109
mysql -u root -e "GRANT ALL PRIVILEGES ON asterisk.* TO [email protected] IDENTIFIED BY '${ASTERISK_DB_PW}';"
mysql -u root -e "GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO [email protected] IDENTIFIED BY '${ASTERISK_DB_PW}';"
mysql -u root -e "flush privileges;"

Any of these steps could potentially break something, and I am not responsible if you run them and they do. That said, I think you’re safe :wink: Can’t be any more broken than it is right now, right? :smiley:

sudo -s might be your friend here, too.

1 Like

I run that first command and I get this output:

    [email protected]:/usr/src/freepbx# mysql -u asteriskuser -ppassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 348
Server version: 5.5.40-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

I’ve tried going over the steps again, but no luck.

My guess is that ${ASTERISK_DB_PW} was undefined when you ran the script

export ASTERISK_DB_PW=‘password’

first or replace it with whatever it really is when you run ./install

I’ve tried it both ways multiple times. Should I remove mysql along with the databases and users? Would that give me a fresh enough environment to try it over again?

If that’s a literal command line, your password IS password :wink: That MySQL prompt means that you logged in successfully.

If you do what Dicko said, it should work.

replace the command line with this:

Also, if that fails and the amportal.conf file have been generated already, check to see if that password matches (if not, update the config file):

Alternatively, as a last resort, log into MySQL again, and do this to set it to the FreePBX default:

At this point, I’m pretty confident that it sin’t the password. Basically, everything that’s been suggested so far, I’ve already tried with just as much success. And I really appreciate the help, guys.

[email protected]:/usr/src/freepbx# ./install_amp --installdb --username=asteriskuser --password=amp109
Checking for PEAR DB..OK
Checking for PEAR Console::Getopt..OK
Using username: asteriskuser
Using password: ******
Checking user..OK
Checking if Asterisk is running..running with PID: 6431..OK
Checking for /etc/amportal.conf..OK
Reading /etc/amportal.conf..parsed amp_conf variables from /etc/amportal.conf:
amp_conf [AMPDBHOST] => [obsidian]
amp_conf [AMPDBENGINE] => [mysql]
amp_conf [AMPENGINE] => [asterisk]
amp_conf [AMPMGRUSER] => [admin]
amp_conf [AMPMGRPASS] => [amp111]
amp_conf [AMPBIN] => [/var/lib/asterisk/bin]
amp_conf [AMPSBIN] => [/usr/local/sbin]
amp_conf [AMPWEBROOT] => [/var/www/html]
amp_conf [AMPCGIBIN] => [/var/www/cgi-bin ]
amp_conf [FOPWEBROOT] => [/var/www/html/panel]
amp_conf [FOPPASSWORD] => [passw0rd]
amp_conf [AUTHTYPE] => [database]
amp_conf [AMPEXTENSIONS] => [extensions]
amp_conf [AMPDBUSER] => [asteriskuser]
amp_conf [AMPDBPASS] => [amp109]
amp_conf [AMPWEBADDRESS] => [192.168.1.2]
amp_conf [AMPDBNAME] => [asterisk]
amp_conf [ASTETCDIR] => [/etc/asterisk]
amp_conf [ASTMODDIR] => [/usr/lib/asterisk/modules]
amp_conf [ASTVARLIBDIR] => [/var/lib/asterisk]
amp_conf [ASTAGIDIR] => [/var/lib/asterisk/agi-bin]
amp_conf [ASTSPOOLDIR] => [/var/spool/asterisk]
amp_conf [ASTRUNDIR] => [/var/run/asterisk]
amp_conf [ASTLOGDIR] => [/var/log/asterisk]
OK
Checking for /etc/asterisk/asterisk.conf..OK
Reading /etc/asterisk/asterisk.conf..OK
Using asterisk as PBX Engine
Checking for Asterisk version..12.8.0
Checking for selinux..OK
Connecting to database..FAILED
Try running ./install_amp --username=user --password=pass  (using your own user and pass)
[FATAL] Cannot connect to database
[email protected]:/usr/src/freepbx#

Edit: Just in case this it a problem, there was a password for the root mysql account, but I removed it yesterday. I don’t know why that would still be interfering, but I’m running out of ideas.

Try without --installdb?

I’ve tried that as well with no success. I’m starting to think about doing another clean ubuntu install.

Okay, I think I have this debugged.

Looking at your output there and the install_amp script…

sed -i 's/AMPDBHOST=obsidian/AMPDBHOST=localhost/g' /etc/amportal.conf
./install_amp --installdb --username=asteriskuser --password=${ASTERISK_DB_PW}

“obsidian” may not be resolving to an IP for the box. Since it’s not a remote database, no reason NOT to do localhost.

1 Like

Thank you so much! I thought that this might be an issue, so yesterday I went into webmin and allowed it to accept form any host, but that didn’t work. I guess I was on the right track, but i gave up on that idea too soon. Again, thanks for all the help :smiley:

You’re welcome :smile:

Dicko and I will flay ourselves appropriately for missing this in the original post :stuck_out_tongue: Or maybe Dicko, we can flay each other? :trollface:

The problem wasn’t that the connection was getting rejected (fix it to only accept local connections, btw, 127.0.0.1), it’s that the client portion of the script couldn’t resolve it and as such couldn’t connect.

Same issue here. I used the tip from Overkill and added an extra parameter (as per script documentation) on the cmd line to point to the localhost:

./install_amp --dbhost=127.0.0.1 --installdb --username=asteriskuser --password=xxxxxxxx

.