MySQL Engine

From ESM Wiki
Jump to: navigation, search

Contents

Introduction

MySQL engine is an engine that encapsulates different methods for working with MySQL database. MySQL engine element is <mysql>:

<mppd>
    <engines>
        <mysql id="db">
            ...
        </mysql>
    </engines>
</mppd>

Common options

Common options affect all methods of an engine that depend on them. In the following XML all common options are specified. Their meaning and properties are specified as comments under corresponding option:

<mppd>
    <engines>
        <mysql id="db">

            <!-- Specifies: options for connections to a database. -->
            <connection>

                <!-- Specifies: remote host where database server is running. -->
                <!-- Value: DNS name or IP address. -->
                <!-- Default: is taken from defaults file. -->
                <host>127.0.0.1</host>

                <!-- Specifies: remote port that database server listens for. -->
                <!-- Value: integer. -->
                <!-- Default: is taken from defaults file. -->
                <port>50270</port>

                <!-- Specifies: remote database to work with. -->
                <!-- Value: string. -->
                <!-- Default: is taken from defaults file. -->
                <database>mpp</database>

                <!-- Specifies: unix socket to connect to local database server. -->
                <!-- Value: socket path. -->
                <!-- Default: is taken from defaults file. -->
                <unix_socket>/var/mysql.socket</unix_socket>
 
                <!-- Specifies: defaults file path. Defaults related to mysql client are honored.-->
                <!-- Value: file path. -->
                <!-- Default: /etc/my.cnf -->
                <defaults_file>/etc/my.cnf</defaults_file>

                <!-- Specifies: number of concurrently running connections.-->
                <!-- Value: integer. -->
                <!-- Default: equal to the number of processing threads -->
                <concurrency>5</concurrency>
 
                <!-- Specifies: options for timeouts.-->
                <timeout>
 
                    <!-- Specifies: timeout in seconds for connection to a server.-->
                    <!-- Value: integer. -->
                    <!-- Default: 60 sec -->
                    <connect>60</connect>

                    <!-- Specifies: timeout in seconds for reading from a server. Has no effect currently. -->
                    <!-- Value: integer. -->
                    <!-- Default: 60 sec -->
                    <read>60</read>

                    <!-- Specifies: timeout in seconds for writing to a server. Has no effect currently. -->
                    <!-- Value: integer. -->
                    <!-- Default: 60 sec -->
                    <write>60</write>

                </timeout>
 
                <!-- Specifies: server/database user. -->
                <!-- Value: string. -->
                <!-- Default: NULL (try to connectin without specifying user). -->
                <user>mpp</user>


                <!-- Specifies: ID of a user's password. -->
                <!-- Value: string. -->
                <!-- Default: NULL (try to connect without specifying a password). -->
                <password_id>mpp_pw_id</password_id>
 
                <!-- Specifies: Additional queries to be executed right after connection is established. -->
                <!--            Multiple queries may be specified with multiple options. -->
                <!-- Value: string. -->
                <!-- Default: Queries that are always executed are: -->
                <!--              SET NAMES 'utf8' -->
                <!--              SET SESSION sql_mode='STRICT_ALL_TABLES,STRICT_TRANS_TABLES' -->
                <init_query>SET NAMES 'latin1'</init_query>

            </connection>

        </mysql>
    </engines>
</mppd>

Engine maintains a pool of connections. Number of connections in the pool is specified by <concurrency> option. An engine method to do its job each time retrieves a connection object from the pool, does the job and then puts the object back.

Query method

Query method performs arbitrary MySQL query to a remote MySQL database server. It does the following:

  • retrieves a connection from the pool of connections maintained by enclosing MySQL engine;
  • evaluates query template and sends obtained value to a database through retrieved connection;
  • reads and process response from a database;
  • provides embeded mechanisms for extracting data from response table and exporting it as engine results.

Query method is started with <query> sub-element for <mysql>:

<mppd>
    <engines>
        <mysql id="db">
            ...
            <query id="my_query">
                ...
            </query>
            ...
        </mysql>
    </engines>
</mppd>

Password File

<passwords> Passwords directive is stored in <common> section of mppd.conf.xmlf. It is a path to a file that contains named passwords. Format of the file is: two space separated strings per line. First string is password id and second string is password itself (plain text). If password must contain spaces it must be quoted with "...". Consequently '"' quote in password must be escaped with '\"' sequence. If one would like to comment out password entry one should put '#' at the beginning of a line. Password id's appears in XML config wherever corresponding password should be used. In that way password values will not appear in XML file (only id's) for every feature that uses this functionality.

Personal tools