Unable to take calls when MYSQL server is unreachable

We store cdr records in a mysql database on a remote server. When mysql server becomes unreachable, it’s impossible to make and take calls. Only unloading of cdr_mysql module helps while the server is unreachable. When I connect to the console, of course there are messages like ‘cannot connect to database …’. I’m using asterisk 1.8.15.0 on Gentoo.
Any help will be appreciated.