How to query the Asterisk MySQL database?

Sometimes it is useful to lookup and alter information directly on the Asterisk MySQL database.

Queries can be done by GUI or Command line.

GUI query

To simplify things you can install a single file GUI tool.  For security reasons the file should be deleted after each use.

cd /var/www/html
wget https://www.adminer.org/static/download/4.2.3/adminer-4.2.3.php

Browse to the file as follows:

http://your_PBX_server_ip/adminer-4.2.3.php

See the Command line query section below for instructions on finding the username/password.

If you do not remove the adminer file after use it would be very easy for a hacker to find and gain access using publicly know mysql passwords.

rm -f /var/www/html/adminer-4.2.3.php

Alternatively make it non-browsable when not in use.

chmod 000 /var/www/html/adminer-4.2.3.php

To make it browsable again.

chmod 644 /var/www/html/adminer-4.2.3.php

There are alternative ways to secure this file while still making it easy to use. They are beyond the scope of this FAQ.


Command line query

If you know your MySQL root password you can login using: 

mysql -p asterisk

Alternatively you can look up the asterisk database username/password from /etc/freepbx.conf.  Depending on the distribution and version it may be called something else.  There is also /etc/amportal.conf which contains a lot more information.

So for example assuming the traditional default username/password of asteriskuser/amp109:

mysql -u asteriskuser -p asterisk
amp109
>

The > character indicates we are logged into the MySQL console ready to run queries.

To view all tables in the asterisk MySQL database. 

> show tables;

To view all values in the "sip" table.

> select * from sip;

To view the column headings in the "sip" table.

> show columns from sip;

Note that the second column heading is called "keyword".

To view the nat settings of all the devices in the "sip" table.

> select * from sip where keyword = 'nat';

 

  • mysql, query, search, information

Articles connexes

I have a bunch of anonymous call attempts showing up in my call logs

I have a bunch of calls that look something like this in the call logs. 2011-11-18...

Do I need to do anything on the server/linux side of things?

You should not have to do anything on the server/linux side unless you want to tweak things or...

How hard is it to upgrade my server?

Upgrading resources such as memory, processing, hard drive space is instantaneous and does not...

Do you automatically upgrade our software when a newer version comes out?

Software upgrades are not automatic because they usually require service interruption.  We can...

Do you provided automatic backups.

Our premium plan includes automatic online backups.  All other plans can be backed up manually...