# cd usr/ports/databases/mysql50-server
# make install clean
# mysql
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 59
Server version: 5.0.45 FreeBSD port: mysql-server-5.0.45
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
mysql>
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123');
mysql>
exit
Definimos a senha de root como 123.
Adicione no /etc/rc.conf as seguintes linhas:
mysql_enable="YES"
Crie um arquivo cdr.sql com o seguinte conteúdo:
create database asteriskcdrdb;
use asteriskcdrdb;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `cdr`
--
DROP TABLE IF EXISTS `cdr`;
CREATE TABLE `cdr` (
`calldate` datetime NOT NULL default '0000-00-00 00:00:00',
`clid` varchar(80) NOT NULL default '',
`src` varchar(80) NOT NULL default '',
`dst` varchar(80) NOT NULL default '',
`dcontext` 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 '',
`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',
`accountcode` varchar(20) NOT NULL default '',
`uniqueid` varchar(32) NOT NULL default '',
`userfield` varchar(255) NOT NULL default '',
KEY `calldate` (`calldate`),
KEY `dst` (`dst`),
KEY `accountcode` (`accountcode`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
Salve o arquivo e execute:
# mysql -p < cdr.sql
Enter password:
Pronto, a tabela para armazenagem do cdr já está criada.
Agora, vamos configurar o asterisk para isso.
# cd /usr/local/etc/asterisk
# ee cdr_mysql.conf
E insira isso no final do arquivo:
[global]
hostname = localhost
dbname = asteriskcdrdb
user = root
password = 123
port = 3306
Entre no asterisk com "asterisk -r" e dê um "restart now".
Entre novamente, e verifique:
asterisk*CLI>
cdr mysql status
Connected to asteriskcdrdb@localhost, port 3306 using table cdr for 8 seconds.
Wrote 0 records since last restart.
asterisk*CLI>
Pronto, seu asterisk já está gravando o CDR em MySQL.