mysql-mimic is a pure Python implementation of the MySQL server protocol. It enables developers to create fake MySQL servers to intercept connections, log queries, serve custom data, or test database clients without requiring a real MySQL instance. The current version, 3.0.2, primarily features an asynchronous API and aims for robust protocol emulation. Releases generally follow major breaking changes or significant feature additions, with major versions appearing every 2-3 years.
pip install mysql-mimicVerified import paths — ran on the pinned version, not inferred.
This quickstart sets up a basic MySQL Mimic server that listens on port 3307 (or `MIMIC_PORT` env var). It uses a custom authenticator to allow any username with a pre-defined password (`MIMIC_TEST_PASSWORD` env var or 'super-secret-password'). The `on_query` method demonstrates how to respond to client queries with a list of tuples, mimicking a database result set. Remember to set the environment variable for the password before running.
Rewrite custom server and authenticator methods using `async def` and ensure the server is run in an `asyncio` event loop (e.g., `server.serve_forever_async()` or `asyncio.run(server.serve())`).
Update import statements: `from mysql_mimic.auth import Authenticator` and `from mysql_mimic.ssl import SSLContextProvider`.
Ensure `on_query` always returns a `list` where each element is a `tuple` (e.g., `return [('column1', 'column2'), ('value1', 'value2')]`). For a single string result, use `return [(my_string_result,)]`.It is highly recommended to use an alternative port like 3307 for `mysql-mimic` by passing `port=3307` to the `MySQLServer` constructor, or configuring via environment variables.
No dependency data recorded yet.