mysql

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.

Caution

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

Initialize the instance.

Parameters

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.

Caution

Read-only support is limited to DML sql operations.

Important

  • 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.

Parameters
  • 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.

Yields

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