src/modules/db_mysql/README
b55c09b4
 mysql Module
 
 Daniel-Constantin Mierla
 
    <miconda@gmail.com>
 
 Edited by
 
 Daniel-Constantin Mierla
 
    <miconda@gmail.com>
 
9cb2a163
    Copyright © 2006 Voice Sistem SRL
b55c09b4
      __________________________________________________________________
 
    Table of Contents
 
    1. Admin Guide
 
         1. Overview
         2. Dependencies
 
               2.1. Kamailio Modules
               2.2. External Libraries or Applications
 
ba7961bb
         3. Parameters
b55c09b4
 
               3.1. ping_interval (integer)
82d2a429
               3.2. server_timezone (integer)
               3.3. timeout_interval (integer)
               3.4. auto_reconnect (integer)
               3.5. insert_delayed (integer)
               3.6. update_affected_found (integer)
e3cf23b1
               3.7. opt_ssl_mode (integer)
b55c09b4
 
e3cf23b1
         4. Functions
         5. Installation
         6. Reading configuration from my.cnf
b55c09b4
 
    List of Examples
 
    1.1. Set ping_interval parameter
82d2a429
    1.2. Set server_timezone parameter
    1.3. Set timeout_interval parameter
    1.4. Set auto_reconnect parameter
    1.5. Set insert_delayed parameter
    1.6. Set update_affected_found parameter
a10d6860
    1.7. Set opt_ssl_mode parameter
    1.8. Set a my.cnf group in db_url parameter
    1.9. Adding a kamailio group to my.cnf
    1.10. Using [client] and specific group
b55c09b4
 
 Chapter 1. Admin Guide
 
    Table of Contents
 
    1. Overview
    2. Dependencies
 
         2.1. Kamailio Modules
         2.2. External Libraries or Applications
 
ba7961bb
    3. Parameters
b55c09b4
 
         3.1. ping_interval (integer)
82d2a429
         3.2. server_timezone (integer)
         3.3. timeout_interval (integer)
         3.4. auto_reconnect (integer)
         3.5. insert_delayed (integer)
         3.6. update_affected_found (integer)
e3cf23b1
         3.7. opt_ssl_mode (integer)
b55c09b4
 
e3cf23b1
    4. Functions
    5. Installation
    6. Reading configuration from my.cnf
b55c09b4
 
 1. Overview
 
    This is a module which provides MySQL connectivity for Kamailio. It
    implements the DB API defined in Kamailio.
 
 2. Dependencies
 
    2.1. Kamailio Modules
    2.2. External Libraries or Applications
 
 2.1. Kamailio Modules
 
    The following modules must be loaded before this module:
      * No dependencies on other Kamailio modules.
 
 2.2. External Libraries or Applications
 
    The following libraries or applications must be installed before
    running Kamailio with this module loaded:
8868e624
      * mysql - the development libraries for the MySQL database. In some
b55c09b4
        Linux distributions named "libmysqlclient-dev".
 
ba7961bb
 3. Parameters
b55c09b4
 
    3.1. ping_interval (integer)
82d2a429
    3.2. server_timezone (integer)
    3.3. timeout_interval (integer)
    3.4. auto_reconnect (integer)
    3.5. insert_delayed (integer)
    3.6. update_affected_found (integer)
e3cf23b1
    3.7. opt_ssl_mode (integer)
b55c09b4
 
 3.1. ping_interval (integer)
 
    Time interval in seconds to send ping messages to MySQL server in order
    to keep the connection open.
 
    Default value is 300 (5 min).
 
    Example 1.1. Set ping_interval parameter
 ...
 modparam("db_mysql", "ping_interval", 600)
 ...
 
82d2a429
 3.2. server_timezone (integer)
 
8868e624
    Control if kamailio converts a time to string using the local timezone
82d2a429
    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)
 
    Example 1.2. Set server_timezone parameter
 ...
 modparam("db_mysql", "server_timezone", 1)
 ...
 
 3.3. timeout_interval (integer)
b55c09b4
 
    Time interval (in seconds) after that an 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
9cb2a163
    “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
b55c09b4
    support it at all.
 
    Default value is 2 (6 sec).
 
82d2a429
    Example 1.3. Set timeout_interval parameter
b55c09b4
 ...
 modparam("db_mysql", "timeout_interval", 2)
 ...
 
82d2a429
 3.4. auto_reconnect (integer)
b55c09b4
 
    Configure whether the module should automatically reconnect to MySQL
    server if the connection was lost.
 
    Default value is 1 (1 - on / 0 - off).
 
82d2a429
    Example 1.4. Set auto_reconnect parameter
b55c09b4
 ...
 modparam("db_mysql", "auto_reconnect", 0)
 ...
 
82d2a429
 3.5. insert_delayed (integer)
61c706ef
 
    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).
 
82d2a429
    Example 1.5. Set insert_delayed parameter
61c706ef
 ...
 modparam("db_mysql", "insert_delayed", 1)
 ...
 
82d2a429
 3.6. update_affected_found (integer)
3e0f0954
 
    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).
 
82d2a429
    Example 1.6. Set update_affected_found parameter
3e0f0954
 ...
 modparam("db_mysql", "update_affected_found", 1)
 ...
 
e3cf23b1
 3.7. opt_ssl_mode (integer)
a10d6860
 
    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.
 
a86029bb
    Note: this option is supported only by libmysqlclient, not by
    libmariadbclient.
 
a10d6860
    Default value is 0 (0 - off).
 
    Example 1.7. Set opt_ssl_mode parameter
 ...
 modparam("db_mysql", "opt_ssl_mode", 1)
 ...
 
e3cf23b1
 4. Functions
b55c09b4
 
    No function exported to be used from configuration file.
 
e3cf23b1
 5. Installation
b55c09b4
 
8868e624
    Because it depends on an external library, the mysql module is not
b55c09b4
    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"'.
 
e3cf23b1
 6. Reading configuration from my.cnf
b55c09b4
 
    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:
      * mysql://user:pass@[group]host:port/db
      * mysql://user:pass@[group]:port/db
      * mysql://user:pass@[group]/db
      * mysql://[group]/db
 
a10d6860
    Example 1.8. Set a my.cnf group in db_url parameter
b55c09b4
 ...
 modparam("usrloc", "db_url", "mysql://[kamailio]/kamailio)
 ...
 
a10d6860
    Example 1.9. Adding a kamailio group to my.cnf
b55c09b4
 ...
 [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.
 
a10d6860
    Example 1.10. Using [client] and specific group
b55c09b4
 ...
 [client]
4bb8bc9a
 socket = /run/mysql/mysqld.sock
b55c09b4
 
 [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.