MySQL module (native).

exception spicerack.mysql.MysqlError[source]

Bases: spicerack.exceptions.SpicerackError

Custom exception class for errors of this module.

class spicerack.mysql.Mysql(*, dry_run: bool = True)[source]

Bases: object

Class to manage MySQL servers.


This class only has DRY-RUN support for DML sql operations.

Initialize the instance.


dry_run (bool, optional) -- whether this is a DRY-RUN.

connect(*, read_only: bool = False, charset: str = 'utf8mb4', read_default_file: Optional[str] = '', read_default_group: Optional[str] = None, ssl: Optional[Dict] = None, **kwargs: Any) Generator[source]

Context-manager for a mysql connection to a remote host.


Read-only support is limited to DML sql operations.


  • This does not commit changes, that is the caller's responsibility.

  • The caller should also take care of rolling back transactions on error as appropriate.

  • read_only (bool, optional) -- True if this connection should use read-only transactions. Note: This parameter has no effect if DRY-RUN is set.

  • charset (str, optional) -- Query charset to use.

  • read_default_file (str, optional) -- my.cnf-format file to read from. Defaults to ~/.my.cnf. Set to None to disable.

  • read_default_group -- Section of read_default_file to use. If not specified, it will be set based on the target hostname.

  • ssl (dict, optional) -- SSL configuration to use. Defaults to using the puppet CA. Set to {} to disable.

  • **kwargs -- Options passed directly to pymysql.connections.Connection.


pymysql.connections.Connection -- a context-managed mysql connection.