I have set up kamailio 3.1.2 on an install of Debian Squeeze, using the default config but with the following defines enabled:

WITH_MYSQL
WITH_AUTH
WITH_USRLOCDB
WITH_NAT

Everything works as expected when starting Kamailio from a terminal, e.g.
service kamailio start

But after a reboot, the service fails to start and all SIP requests are dropped with a ICMP port unreachable error.

The following is an extract of /var/log/syslog when this problem occurs. It looks like Kamailio is failing to access the mysql socket, as the mysql service has not yet started?

Apr 12 10:08:31 SIPServer /usr/sbin/kamailio[1347]: ERROR: db_mysql [km_my_con.c:109]: driver error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Apr 12 10:08:31 SIPServer /usr/sbin/kamailio[1347]: ERROR: <core> [db.c:289]: could not add connection to the pool
Apr 12 10:08:31 SIPServer /usr/sbin/kamailio[1347]: ERROR: usrloc [dlist.c:486]: failed to open database connection
Apr 12 10:08:31 SIPServer /usr/sbin/kamailio[1347]: ERROR: registrar [reg_mod.c:396]: failed to register domain
Apr 12 10:08:31 SIPServer /usr/sbin/kamailio[1347]: ERROR: <core> [route.c:1161]: fixing failed (code=-1) at cfg:/etc/kamailio/kamailio.cfg:569
Apr 12 10:08:31 SIPServer /usr/sbin/kamailio[1347]: ERROR: <core> [route.c:1161]: fixing failed (code=-1) at cfg:/etc/kamailio/kamailio.cfg:572
Apr 12 10:08:31 SIPServer /usr/sbin/kamailio[1347]: ERROR: <core> [route.c:1161]: fixing failed (code=-1) at cfg:/etc/kamailio/kamailio.cfg:574
Apr 12 10:08:34 SIPServer mysqld_safe: Starting mysqld daemon with databases from /var/lib/mysql
Apr 12 10:08:34 SIPServer mysqld: 110412 10:08:34 [Note] Plugin 'FEDERATED' is disabled.
Apr 12 10:08:36 SIPServer mysqld: 110412 10:08:36  InnoDB: Started; log sequence number 0 44233
Apr 12 10:08:36 SIPServer mysqld: 110412 10:08:36 [Note] Event Scheduler: Loaded 0 events
Apr 12 10:08:36 SIPServer mysqld: 110412 10:08:36 [Note] /usr/sbin/mysqld: ready for connections.
Apr 12 10:08:36 SIPServer mysqld: Version: '5.1.49-3'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Debian)

Both the Kamailio and mysql services start with priority 18 on run levels 2345. I tried adjusting the Kamailio service to priority 19, but the problem still occurs.

I am relatively new to Kamailio and mysql as well as Linux / Debian administration, so I'm not really sure how to solve this problem. Any ideas would be greatly appreciated.

Regards,
Rick Aldred