Skip to content

Export and migration

The Export / Migrate tab copies databases or tables of one open MySQL/MariaDB connection to an SQL file, the clipboard or another open connection. The source is only read. Step by step: Export or migrate a MySQL database.

Export / Migrate tab with a plan for an SQL file

It opens from Export… (target: SQL file) or Migrate… (target: connection) in the context menu of a database or table in the Databases window. There is one such tab per window; it is not saved in the layout and does not move to another window. Closing it cancels a running job.

Field Values
Source A connection tab of this window; its databases with checkboxes, expandable to tables (view or ≈rows). System databases (information_schema, performance_schema, mysql, sys) are refused.
Target SQL file (chosen in the save panel at the start), Clipboard (up to 16 MiB), Connection
Connection Another open connection; must be a saved session with Allow write. A target tab opened with Connect as… writes as that login (shown as app (server account app@%) on db.example:3306 (Connect as))
Database Only with one source database: a new name on the target (shop → shop_copy); view definitions are rewritten from `old`. to `new`. outside literals

A checked database copies everything in it (with routines and triggers when those options are on); picked tables copy only those tables, their views and triggers.

Option Default What it does
DROP DATABASE off DROP DATABASE IF EXISTS first (removes also what is not copied). Turning it on disables CREATE DATABASE as a choice (it is needed then).
CREATE DATABASE on CREATE DATABASE IF NOT EXISTS with the source’s character set and collation. Off + missing target database = refused at plan time.
DROP TABLE / VIEW on DROP … IF EXISTS before each table, view, routine and trigger.
CREATE TABLE / VIEW on SHOW CREATE of the source, sent as is.
Views on Views after the tables, in dependency order (from VIEW_DEFINITION).
Procedures and functions off Only for whole databases.
Triggers off After the data, so they do not fire on copied rows.
Keep DEFINER off Off: DEFINER=… is removed from the header, so objects belong to the target account. On: needs SET_USER_ID or SUPER on the target.
Data INSERT INSERT, REPLACE, INSERT IGNORE, None (structure only)
Max INSERT size 1048576 bytes Longest statement (4 KiB to 1 GiB); for a connection kept below the target’s max_allowed_packet minus 1 KiB.
Rows per INSERT 1000 Rows in one statement.
Rows per SELECT 5000 Rows read per chunk.

Events are not copied. Only MySQL/MariaDB to MySQL/MariaDB.

Prepare plan reads the catalogs over the tabs’ connections (read-only) and shows the steps (kind, database, object, estimated rows), a summary of the statements, warnings (no primary key, ProxySQL source, MyISAM, procedures copied with their bodies, skipped objects, …) and First statements in full. The plan is held for 30 minutes; any change of the form drops it.

For a connection target, Start shows the plan again with n step(s). Each statement commits on its own; a stop leaves the steps done so far on the target. and needs I checked the plan and the target, plus The target is a PRODUCTION session: write anyway for production, then Write to target. The target’s flags are read from sessions.json at plan time and again at start; a target behind ProxySQL, a quick connection, or the same server and database as the source is refused (server identity from @@hostname, @@port, @@datadir, names compared without case).

Source (a separate connection with the tab’s login and TLS; the tab stays as it is):

SET NAMES utf8mb4;
SET SESSION time_zone = '+00:00';
SET SESSION sql_mode = '';
SET SESSION TRANSACTION READ ONLY; -- read back afterwards
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
SET SESSION net_write_timeout = 600; -- a failure is only a warning
START TRANSACTION WITH CONSISTENT SNAPSHOT, READ ONLY;

All tables are read as of one moment. A server that does not know READ ONLY in START TRANSACTION (error 1064) gets START TRANSACTION WITH CONSISTENT SNAPSHOT; the session flag still holds. Behind ProxySQL there is no transaction and no session flag (they would pin the session to one hostgroup): the log warns that each SELECT may read another backend.

Rows: tables whose primary key columns are all integer, DECIMAL, date/time, CHAR/VARCHAR or BINARY/VARBINARY are read in chunks by key (WHERE pk > last ORDER BY pk LIMIT n; composite keys a > x OR (a = x AND b > y)), never with OFFSET. Other tables are read with one streamed SELECT (warning in the log). Rows go straight into INSERT statements; a table is never held in memory. Generated columns are left out.

Values: numbers as the server printed them, FLOAT read as col + 0E0, binary, BIT, spatial and VECTOR columns as 0x…, text in '…' with \, NUL, CR, LF and Ctrl+Z escaped, invalid UTF-8 as 0x….

Target (a separate connection):

SET NAMES utf8mb4;
SET SESSION time_zone = '+00:00';
SET SESSION sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
SET SESSION foreign_key_checks = 0;
SET SESSION unique_checks = 0;
SET autocommit = 1;
-- each value read back before the first write
-- … the plan …
SET SESSION foreign_key_checks = 1;
SET SESSION unique_checks = 1;

No transaction: every statement commits on its own. @@GLOBAL.read_only = 1 on the target gives the warning writes fail unless the account has SUPER / CONNECTION_ADMIN. After a statement with warnings, SHOW WARNINGS LIMIT 5 goes into the log. Procedures and triggers are created with their own sql_mode from SHOW CREATE. SHOW CREATE of a table or view must be one statement creating that object, otherwise it is not sent; procedure and trigger bodies are sent as they are (copying a procedure runs its definition on the target). Before DROP TABLE on the target the source’s SHOW CREATE TABLE is read and checked.

SQL file: written to .<name>.<random>.tmp in the target folder (0600, created exclusively), synced and renamed at the end; cancel or error removes it (after a crash it stays as .….tmp). A header like mysqldump sets character set, time zone, FOREIGN_KEY_CHECKS, UNIQUE_CHECKS and sql_mode and restores them in the footer; procedures and triggers sit between DELIMITER markers that do not occur in their bodies. Clipboard: the same text, copied when the run finishes, up to 16 MiB.

One statement on either side may take up to 10 minutes; past that the run stops and names the connection id for KILL QUERY.

The step table shows state, rows, bytes and time per step and the server error (code, SQLSTATE, message). The log below lists every step with time stamps; Copy log copies log and step table. Both connection consoles log the statements as [export] sql> … and [migration] sql> … (INSERTs as a summary: table, rows, bytes, no data). Passwords never appear.

Cancel stops the current statement (KILL QUERY over the tab’s connection; a streamed SELECT is killed too). After a failed migration, Resume from step N (or from here on any step) runs the plan again from that step, in a new snapshot. With DROP TABLE / VIEW off, rows already copied into the resumed table are inserted again: choose REPLACE or INSERT IGNORE. Files and the clipboard always start at step 1.

After a migration COUNT(*) runs on both sides for every copied table; COUNT(*) source / target marks differences. Mr. Paperclip reports the end (rows, bytes, time, file path, tables with a different count) or the stop (step, server error).

Scroll or pinch to zoom · drag to move · double-click to zoom · Esc or click outside to close