mysql¶
MySQL module (native).
- exception spicerack.mysql.MysqlError[source]¶
Bases:
SpicerackError
Custom exception class for errors of this module.
- class spicerack.mysql.Mysql(*, dry_run: bool = True) None [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
, default:True
) -- whether this is a DRY-RUN.
- connect(*, read_only: bool = False, charset: str = 'utf8mb4', read_default_file: str | None = '', read_default_group: str | None = None, ssl: dict | None = None, **kwargs: Any) collections.abc.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
, default:False
) -- True if this connection should use read-only transactions. Note: This parameter has no effect if DRY-RUN is set.charset (
str
, default:'utf8mb4'
) -- Query charset to use.read_default_file (
typing.Optional
[str
], default:''
) --my.cnf
-format file to read from. Defaults to~/.my.cnf
. Set toNone
to disable.read_default_group (
typing.Optional
[str
], default:None
) -- Section of read_default_file to use. If not specified, it will be set based on the target hostname.ssl (
typing.Optional
[dict
], default:None
) -- SSL configuration to use. Defaults to using the puppet CA. Set to{}
to disable.**kwargs (
typing.Any
) -- Options passed directly topymysql.connections.Connection
.
- Yields:
pymysql.connections.Connection
-- a context-managed mysql connection.- Return type: