We assumed that you have already installed and running MySQL server. We will need to change some files in mysql and asterisk configuration.

[root@asterisk1 asterisk]# cd /etc/asterisk/

With editor you prefer open cdr_mysql.conf for editing, and change next lines:

hostname=asterisk1 hostname for server
dbname=asteriskdb database for log in calls
password=qwerty password for log in MySQL
user=asterisk user which will write to database
port=3306 default port for MySQL

After this we need to add asteriskdb in mysql and set privileges for user asterisk.

[root@asterisk1 ~]# mysql -u root -p
mysql> create database asteriskdb;
mysql> grant all privileges on asteriskdb.* to asterisk identified by 'qwerty'; Give all privileges to user asterisk on DB asteriskdb, where password for user is qwerty
mysql> CREATE TABLE cdr ( uniqueid varchar(32) NOT NULL default '', userfield varchar(255) NOT NULL default '', accountcode varchar(20) NOT NULL default '', src varchar(80) NOT NULL default '', dst varchar(80) NOT NULL default '', dcontext varchar(80) NOT NULL default '', clid varchar(80) NOT NULL default '', channel varchar(80) NOT NULL default '', dstchannel varchar(80) NOT NULL default '', lastapp varchar(80) NOT NULL default '', lastdata varchar(80) NOT NULL default '', calldate datetime NOT NULL default '0000-00-00 00:00:00', duration int(11) NOT NULL default '0', billsec int(11) NOT NULL default '0', disposition varchar(45) NOT NULL default '', amaflags int(11) NOT NULL default '0' ); Add table cdr, which will use for logs for asterisk calls

After this we need to restart asterisk and Mysql, and we can start log in all calls which goes trough Asterisk server

[root@asterisk1 ~]# /etc/init.d/mysqld restart
[root@asterisk1 ~]# /etc/init.d/asterisk restart