mysql
MySQL module (native).
- 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, **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
By default autocommit is off and the commit of changes 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, it will be forces to True.**kwargs (
typing.Any
) --Options passed directly to
pymysql.connections.Connection
. If not set some settings will be set to default values:read_default_file:
~/.my.cnf
. Set toNone
to disable it.read_default_group: If not specified, it will be set to
client
orlabsdbclient
based on the hostname.ssl: uses the puppet CA. Set to
{}
to disable.cursorclass:
pymysql.cursors.DictCursor
- Yields:
pymysql.connections.Connection
-- a context-managed mysql connection.- Raises:
pymysql.err.MySQLError -- if unable to create the connection or set the connection to read only.
- Return type: