cdr_mysql (Failed to connect to mysql database)


#1

This seems to be the last ERROR I encounter on my
system:

[cdr_addon_mysql.so] => (MySQL CDR Backend)
== Parsing ‘/etc/asterisk/cdr_mysql.conf’: Found
May 1 20:55:44 ERROR[371]: cdr_addon_mysql.c:438
my_load_module:
Failed to connect to mysql database asteriskcdrdb on
localhost.

Where does this script go?

CREATE DATABASE asterisk;

GRANT INSERT
ON asterisk.*
TO asteriskaccount
IDENTIFIED BY ‘asteriskpassword’;

USE asterisk;

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 ‘’,
userfield varchar(255) NOT NULL default ‘’
);

ALTER TABLE cdr ADD INDEX ( calldate );
ALTER TABLE cdr ADD INDEX ( dst );
ALTER TABLE cdr ADD INDEX ( accountcode );


my cdr_mysql.conf reads:

;
; Note - if the database server is hosted on the same
machine as the
; asterisk server, you can achieve a local Unix socket
connection by
; setting hostname=localhost
;
; port and sock are both optional parameters. If
hostname is specified
; and is not “localhost”, then cdr_mysql will attempt
to connect to the
; port specified or use the default port. If hostname
is not specified
; or if hostname is “localhost”, then cdr_mysql will
attempt to connect
; to the socket file specified by sock or otherwise
use the default socket
; file.
;
[global]
hostname=localhost
dbname=asteriskcdrdb
table=cdr
password=
user=root
port=3306
sock=/tmp/mysql.sock
userfield=1

Your thoughts?

Otherwise, everything else is running fine.

tx


#2

You need to log into MySQL and then run this script to create the database, table and set permissions. Then in cdr_mysql.conf you need to set the database name, user and password to whatever values you set in the script (see the GRANT INSERT… section of the above script). I would highly suggest you pick a different username and password than the default.

If you stick with the above script your cdr_mysql.conf would look like:

[global]
hostname=localhost
dbname=asterisk
table=cdr
password=asteriskpassword
user=asteriskaccount
port=3306
sock=/tmp/mysql.sock
userfield=1

Scott

Edit: decided to add the cdr_mysql.conf section for clarity!