文档/MySQL / MariaDB
此页面尚未翻译,当前显示英文版本。 查看英文版本
dbflux_driver_mysql
Features
- MySQL and MariaDB relational driver implementations in one crate.
- Supports SQL execution, schema discovery, indexes, foreign keys, check constraints, and unique constraints.
- Supports authentication, SSL, SSH tunneling, and URI/manual connection modes.
- Supports query cancellation through a dedicated cancel path (
KILL QUERYflow). - Includes SQL/code generation for CRUD, indexes, foreign keys, and table DDL operations.
- Routine discovery: lists stored procedures and user-defined functions from
information_schema.ROUTINESincluding parameter types and return type hints (Functions only). - Routine definition: retrieves the full
CREATE FUNCTIONorCREATE PROCEDUREbody viaSHOW CREATE FUNCTION/SHOW CREATE PROCEDURE(read-only; definition is not editable or executable in the viewer). - Multi-statement scripts (several
;-separated statements) are split and executed statement by statement, each through the typed prepared path, returning one result set per statement.
Instance Metrics
Exposes a curated set of live server metrics sourced from SHOW GLOBAL STATUS:
mysql.threads_connected— current open connectionsmysql.threads_running— currently executing queriesmysql.queries_per_sec— queries per second (cumulative counter)mysql.innodb_buffer_pool_hit_ratio— InnoDB buffer pool read efficiencymysql.innodb_rows_read— rows read from InnoDB storage enginemysql.innodb_rows_inserted— rows inserted into InnoDBmysql.innodb_rows_updated— rows updated in InnoDBmysql.innodb_rows_deleted— rows deleted from InnoDBmysql.slow_queries— cumulative slow query countmysql.table_locks_waited— table-level lock contention countermysql.bytes_sent— network bytes sent
Each metric is returned as a single (timestamp_ms, value) row for live charting.
Instance Inspector
Exposes tabular snapshots of running server state:
mysql.processlist— active sessions frominformation_schema.PROCESSLIST(user, host, db, command, time, state, info)
Limitations
-
SQL-only driver; it does not expose document or key-value APIs.
-
Instance metrics return a single data point per call (current snapshot from
SHOW GLOBAL STATUS), not a historical time series. Cumulative counters (e.g.mysql.bytes_sent) grow monotonically — interpret them as deltas between samples rather than absolute rates. -
The
performance_schemaavailability probe runs once at catalog construction time. Whenperformance_schemais absent, performance-schema-specific metrics are omitted fromlist_metrics(). The static metric set (SHOW GLOBAL STATUSbased) is always available. -
A multi-statement script runs each statement sequentially rather than as one atomic server-side batch; statement splitting is text-based and may missplit stored-program bodies that embed
;(e.g.CREATE PROCEDURE ... BEGIN ... END). -
Cancellation depends on server permissions and connection state when
KILL QUERYis issued. -
Code generation is scoped to supported MySQL/MariaDB constructs; unsupported generator IDs return
NotSupported. -
Routine listing covers only FUNCTION and PROCEDURE types. MySQL aggregate functions (registered via
CREATE AGGREGATE FUNCTIONUDF plugin) and window functions are not surfaced ininformation_schema.ROUTINESand are therefore not listed. -
SHOW CREATE FUNCTION/SHOW CREATE PROCEDURErequires theSHOW_ROUTINEprivilege (MySQL 8.0+) or ownership of the routine; without sufficient privileges the definition column returnsNULLand the viewer displays a notice instead of the source.
DDL Capabilities
Non-Transactional DDL
CRITICAL: MySQL DDL operations are NOT transactional — they cannot be rolled back:
BEGIN;
ALTER TABLE users ADD COLUMN phone VARCHAR(20) NULL;
-- DDL is committed immediately, ROLLBACK has no effect!
ROLLBACK; -- Too late, column already added
Exception: RENAME TABLE is atomic (safe to use in transactions).
ALTER TABLE Behavior
Table rewrites:
- Most
ALTER TABLEoperations rewrite the entire table (locks table for duration) - Use
ALGORITHM=INPLACEandLOCK=NONEfor online DDL (MySQL 5.6+):ALTER TABLE users ADD COLUMN phone VARCHAR(20) NULL, ALGORITHM=INPLACE, LOCK=NONE;
Adding columns:
- Adding column at end of table: Fast (metadata-only)
- Adding column in middle of table: Table rewrite (locks table)
- Use
AFTER column_nameto control position
Adding columns with defaults:
- Table rewrite (locks table)
- Default value is written to all existing rows
Changing column types:
- Always requires table rewrite (locks table)
- Data conversion happens during rewrite
Dropping columns:
- Table rewrite (locks table)
- Data is immediately deleted
Renaming columns:
- Table rewrite (locks table)
- May break views, triggers, and application code
Index Operations
CREATE INDEX:
- Locks table for writes (reads allowed)
- Use
ALGORITHM=INPLACE, LOCK=NONEfor online index creation:CREATE INDEX idx_users_email ON users(email) ALGORITHM=INPLACE, LOCK=NONE;
DROP INDEX:
- Locks table for writes (reads allowed)
- Use
ALGORITHM=INPLACE, LOCK=NONEfor online index removal
Constraints
Foreign keys:
- Adding foreign keys scans both tables (locks both)
- Use
ALGORITHM=INPLACE, LOCK=NONEwhen possible
UNIQUE constraints:
- Requires index creation (locks table)
CHECK constraints (MySQL 8.0.16+):
- Metadata-only (fast)
- Validated on INSERT/UPDATE only
Online DDL (MySQL 5.6+)
ALGORITHM options:
INPLACE— Modify table in place (no copy)COPY— Create new table and copy rows (default for old MySQL versions)INSTANT— Metadata-only (MySQL 8.0+, limited operations)
LOCK options:
NONE— Allow concurrent reads and writesSHARED— Allow reads, block writesEXCLUSIVE— Block reads and writes
Example:
ALTER TABLE users
ADD COLUMN phone VARCHAR(20) NULL,
ALGORITHM=INPLACE,
LOCK=NONE;
Known Limitations
- DDL not transactional (cannot rollback)
- Most
ALTER TABLEops rewrite entire table (locks table) - Adding column in middle of table requires rewrite
- Online DDL support varies by MySQL version
- Use
pt-online-schema-change(Percona Toolkit) for zero-downtime DDL on large tables
Best Practices
- Test on a copy first — DDL cannot be rolled back
- Use online DDL — Add
ALGORITHM=INPLACE, LOCK=NONEwhen supported - Schedule maintenance windows — Run DDL during low-traffic periods
- Monitor table size — Large tables take longer to rewrite
- Use pt-online-schema-change — For zero-downtime DDL on production tables