[SOLVED] Can't connect to local MySQL server

Hello my friends,

I would like to ask for help regarding my Asterisk setup.
Any help is highly appreciated.

I installed Asterisk 18.2.2 LTS, everything is okay including the database that I built through the script and even so Asterisk don’t connect to MariaDB database through the mariadb connector odbc.
I tested if the connector is working using

isql -v asterisk-connector mydatabase-user  password

It connected successfully but in asterisk I still can’t connect and I get this error message:

[Mar 13 00:02:17] ERROR[3462]: res_config_odbc.c:200 realtime_odbc: No database handle available with the name of 'asterisk' (check res_odbc.conf)
[Mar 13 00:02:17] WARNING[3462]: res_odbc.c:1067 odbc_obj_connect: res_odbc: Error SQLConnect=-1 errno=2002 [unixODBC][ma-3.1.11]Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock'

I have reviewed the configurations 100 times and for 2 days I was looking for similar issues but I couldn’t solve it.

from the error it says check res_odbc.conf and here is the content of it:

[asterisk]

enabled => yes

dsn => asterisk

username => xxxxxxxx

password => xxxxxxxx

pre-connect => yes

xxxxxxxx indicating the username and the password I set in the /etc/odbc.ini in [asterisk] block like this

[asterisk]
Description = MySQL connection to 'asterisk' database
Driver = /usr/local/lib64/mariadb/libmaodbc.so
Database = asterisk-database
Username = xxxxxxxx
Password = xxxxxxxx
Server = localhost
Port = 3306
Socket = /run/mysqld/mysqld.sock

The content of /etc/odbcinst.in is the same as /etc/odbc.ini

I set a rule here also for letting asterisk create socket at runtime /etc/tmpfiles.d/asterisk.conf
like that

/var/run/asterisk 0775 asterisk asterisk

Some other information about my environment:
MariaDB 10.3.25 database server
MariaDB Connector ODBC 3.1.11
OS Ubuntu server 20.04 - AWS

I need to mention that I set a profile for asterisk through apparmor as well, it run in complain mode.

Permission of files should be okay since I’ve reviewed them several times, but if you have any concern about that also then let me know.

Also I get hundreds of messages on the CLI even I can’t use it, some of them are a tries to make calls through endpoints from different IPs, Do you think any message here indicates something unusual?:

[Mar 13 00:02:16] NOTICE[3462]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'INVITE' from '<sip:1001@myserver_ip>' failed for 'xxxxxxxxxxxx:60285' (callid: 56578576563-839278996-24337578) - No matching endpoint found
[Mar 13 00:02:16] NOTICE[3462]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'INVITE' from '<sip:1001@myserver_ip>' failed for 'xxxxxxxxxxxx:60285' (callid: 566345643-8392656-244983400) - Failed to authenticate

Any help is highly appreciated.

Regards

UPDATE**

I have solved the issue.

For others who might face the same problem, I have solved it by removing the socket line in /etc/odbc.ini in

Socket = /run/mysqld/mysqld.sock

Also, replaced localhost with the IP address to connect through it. I used localhost IP 127.0.0.1

Server = 127.0.0.1

Don’t forget to reboot your machine,

I would like to mention this post as a reference as well
Reference post

Thanks to erichowey

Everything worked fine for now.

Thanks

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.