# salt.cache.mysql_cache

Minion data cache plugin for MySQL database.

New in version 2018.3.0.

It is up to the system administrator to set up and configure the MySQL infrastructure. All is needed for this plugin is a working MySQL server.

Warning

The mysql.database and mysql.table_name will be directly added into certain queries. Salt treats these as trusted input.

The module requires the database (default `salt_cache`) to exist but creates its own table if needed. The keys are indexed using the `bank` and `etcd_key` columns.

To enable this cache plugin, the master will need the python client for MySQL installed. This can be easily installed with pip:

    pip install pymysql

Optionally, depending on the MySQL agent configuration, the following values could be set in the master config. These are the defaults:

    mysql.host: 127.0.0.1
    mysql.port: 2379
    mysql.user: None
    mysql.password: None
    mysql.database: salt_cache
    mysql.table_name: cache

Related docs can be found in the python-mysql documentation.

To use the mysql as a minion data cache backend, set the master `cache` config value to `mysql`:

    cache: mysql

salt.cache.mysql_cache.contains(bank, key)

  Checks if the specified bank contains the specified key.

salt.cache.mysql_cache.fetch(bank, key)

  Fetch a key value.

salt.cache.mysql_cache.flush(bank, key=None)

  Remove the key from the cache bank with all the key content.

salt.cache.mysql_cache.force_reconnect()

  Force a reconnection to the MySQL database, by removing the client from Salt's __context__.

salt.cache.mysql_cache.ls(bank)

  Return an iterable object containing all entries stored in the specified bank.

salt.cache.mysql_cache.run_query(conn, query, args=None, retries=3)

  Get a cursor and run a query. Reconnect up to `retries` times if needed. Returns: cursor, affected rows counter Raises: SaltCacheError, AttributeError, OperationalError

salt.cache.mysql_cache.store(bank, key, data)

  Store a key value.

salt.cache.mysql_cache.updated(bank, key)

  Return the integer Unix epoch update timestamp of the specified bank and key.