Table of Contents
List of Examples
ping_interval
parameterserver_timezone
parametertimeout_interval
parameterauto_reconnect
parameterinsert_delayed
parameterupdate_affected_found
parameteropt_ssl_mode
parameteropt_ssl_ca
parameterdb_url
parameterTable of Contents
This is a module which provides MySQL connectivity for Kamailio. It implements the DB API defined in Kamailio.
The following modules must be loaded before this module:
No dependencies on other Kamailio modules.
The following libraries or applications must be installed before running Kamailio with this module loaded:
mysql - the development libraries for the MySQL database. In some Linux distributions named "libmysqlclient-dev". MariaDB - the development libraries for the MariaDB database. In some Linux distributions named "libmariadbclient-dev".
Time interval in seconds to send ping messages to MySQL server in order to keep the connection open.
Default value is 300 (5 min).
Control if kamailio converts a time to string using the local timezone or if MySQL will convert it using FROM_UNIXTIME. This option is useful if kamailio and the database are configured for different timezones.
Default value is 0 (use local conversion)
Time interval (in seconds) after that a connection attempt, read or write request is aborted. The value counts three times, as several retries are done from the driver before it gives up.
The read timeout parameter is ignored on MySQL driver versions prior to “5.1.12”, “5.0.25” and “4.1.22”. The write timeout parameter is ignored on versions prior to “5.1.12” and “5.0.25”, the “4.1” release don't support it at all.
Default value is 2 (6 sec).
Configure whether the module should automatically reconnect to MySQL server if the connection was lost.
Default value is 1 (1 - on / 0 - off).
If set to 1, all INSERT SQL queries will be sent to MySQL server as INSERT DELAYED.
Default value is 0 (1 - on / 0 - off).
If set to 1, all UPDATE SQL queries will return the number of matched rows instead of the number of "updated" rows.
Default value is 0 (1 - on / 0 - off).
Example 1.6. Set update_affected_found
parameter
... modparam("db_mysql", "update_affected_found", 1) ...
Control how the connection to MySQL server is done in regards to SSL/TLS. If set to 1, SSL/TLS mode is disabled.
The 'include/mysql.h' starting with MySQL 5.7.11 defines the values for this option as enum: 'mysql_ssl_mode { SSL_MODE_DISABLED=1, SSL_MODE_PREFERRED, SSL_MODE_REQUIRED, SSL_MODE_VERIFY_CA, SSL_MODE_VERIFY_IDENTITY}'.
Note: if the value of this parameter is 1, it enforces SSL_MODE_DISABLED, any other value is passed to the mysql_options(), not checking if it is defined.
MariaDB client configuration uses the following values: 0, 1 use plain, 2/3/4 for MYSQL_OPT_SSL_ENFORCE, 5 for MYSQL_OPT_SSL_VERIFY_SERVER_CERT (see MariaDB Connector/C documentation) Other values are ignored.
Default value is 0 (0 - off).
Configures the CA certs used to verify the MySQL server cert when SSL is enabled.
Required when opt_ssl_mode = 4 or 5 and db_mysql is built with libmysqlclient.
Default value is NULL (NULL - not configured).
Example 1.8. Set opt_ssl_ca
parameter
... modparam("db_mysql", "opt_ssl_ca", "/etc/ssl/certs/mysql-ca.pem") ...
Because it depends on an external library, the mysql module is not compiled and installed by default. You can use one of these options.
- edit the "Makefile" and remove "db_mysql" from "excluded_modules" list. Then follow the standard procedure to install Kamailio: "make all; make install".
- from command line use: 'make all include_modules="db_mysql"; make install include_modules="db_mysql"'.
In order to take into account specific mysql client options, a my.cnf config group can be passed using the db_url module parameter. This is done by setting [group] in front of or instead of the host part. The following examples are valid db_url definitions, which include a my.cnf group:
Example 1.9. Set a my.cnf group in db_url
parameter
... modparam("usrloc", "db_url", "mysql://[kamailio]/kamailio) ...
Example 1.10. Adding a kamailio group to my.cnf
... [kamailio] socket = /path/to/mysql.sock user = kamailiouser password = kamailiopass default-character-set = utf8 ...
In addition to the given group, also the [client] section is read, in the order given in my.cnf. So if you for example specify a socket in both your specific group and the client group, then the value is taken from the last one.
Example 1.11. Using [client] and specific group
... [client] socket = /run/mysql/mysqld.sock [kamailio] socket = /path/to/mysqld.sock user = kamailiouser password = kamailiopass default-character-set = utf8 ...
In the example given above, the socket /path/to/mysqld.sock is used by Kamailio because both [kamailio] and [client] define this option, and the latter overwrites the first.