Asterisk – ODBC + CDR + Mysql on Ubuntu

We recently switched from using cdr_mysql on Asterisk (now depreciated) to crd_obdc + cdr_adaptive_odbc to store CDR logs to MySQL. Below is the process for doing so.

Install needed libraries.

1. apt-get install libmyodbc unixodbc-bin
2. sudo apt-get install unixODBC unixODBC-dev

Lookup socket:

mysqladmin -u root -p version

Update /etc/odbc.ini – set socket to location found in above command:

Description     = ivr_test MySQL ODBC
Driver          = MySQL
Socket          = /var/run/mysqld/mysqld.sock
Server          = localhost
User            = root
Password        = password
Port            = 3306
Database        = ivr_test
Option          = 3

Find you driver & setup paths:

find / -name 'lib*odbc*.so'

and then update /etc/odbcinst.ini (look for the two files “” & “” from the above command and then set the Driver, Setup fields correspondingly):

Description = ODBC for MySQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/
Setup = /usr/lib/x86_64-linux-gnu/odbc/
FileUsage = 1

Install the ODBC driver:

odbcinst -i -d -f /etc/odbcinst.ini

Install your system DSN:

odbcinst -i -s -l -f /etc/odbc.ini


odbcinst -s -q

Try and connect:


Almost there, now on the asterisk side of things:

Update /etc/asterisk/res_odbc.conf

enabled => yes                                                                                                        
dsn => MySQL-ivr_test                                                                                                 
username => username                                                                                                      
password => paswordhere                                                                                           
preconnect => yes 

Update /etc/asterisk/cdr_adaptive_odbc.conf

alias start => calldate


See also IVR set up in Asterisk here.

Thanks to:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>