Migration from MySQL and PostgreSQL: Difference between revisions

From MemCP
Jump to navigation Jump to search
(Refresh MemCP documentation: accuracy, operational guidance, performance profile and maintained API reference)
(Refresh MemCP documentation: accuracy, operational guidance, performance profile and maintained API reference)
 
Line 15: Line 15:
== Live import ==
== Live import ==


<syntaxhighlight lang="scheme">; MySQL: host/port nil use 127.0.0.1:3306
<pre>; MySQL: host/port nil use 127.0.0.1:3306
(mysql_import nil nil "import_user" "secret" "source_db" "target_db")
(mysql_import nil nil "import_user" "secret" "source_db" "target_db")


; PostgreSQL: database, source schema, target database
; PostgreSQL: database, source schema, target database
(psql_import nil nil "postgres" "secret" "source_db" "public" "target_db")</syntaxhighlight>
(psql_import nil nil "postgres" "secret" "source_db" "public" "target_db")</pre>
Optional trailing arguments select or rename individual tables. Use a least-privilege read-only source account and protect credentials from shell and process listings.
Optional trailing arguments select or rename individual tables. Use a least-privilege read-only source account and protect credentials from shell and process listings.


Line 27: Line 27:
<code>load_sql</code> reads MySQL SQL; <code>load_psql</code> reads PostgreSQL SQL and supported pg_dump/archive inputs. A compressed input must be decompressed (<code>zcat</code>/<code>xzcat</code>), not passed through the <code>gzip</code>/<code>xz</code> compression functions.
<code>load_sql</code> reads MySQL SQL; <code>load_psql</code> reads PostgreSQL SQL and supported pg_dump/archive inputs. A compressed input must be decompressed (<code>zcat</code>/<code>xzcat</code>), not passed through the <code>gzip</code>/<code>xz</code> compression functions.


<syntaxhighlight lang="bash">gzip -dk dump.sql.gz
<pre>gzip -dk dump.sql.gz
# Then in the MemCP console:
# Then in the MemCP console:
# (load_sql "target_db" (stream "dump.sql"))</syntaxhighlight>
# (load_sql "target_db" (stream "dump.sql"))</pre>


For large or live migrations, prefer the importer functions above rather than assuming every vendor-specific dump statement is accepted.
For large or live migrations, prefer the importer functions above rather than assuming every vendor-specific dump statement is accepted.
Line 36: Line 36:
== Application connection ==
== Application connection ==


<syntaxhighlight lang="php">$db = new PDO(
<pre>$db = new PDO(
     'mysql:host=127.0.0.1;port=3307;dbname=target_db',
     'mysql:host=127.0.0.1;port=3307;dbname=target_db',
     'root',
     'root',
     'strong-password'
     'strong-password'
);
);
echo $db->query("SELECT 'it works'")->fetchColumn();</syntaxhighlight>
echo $db->query("SELECT 'it works'")->fetchColumn();</pre>
PostgreSQL SQL syntax is available over <code>/psql/&lt;database&gt;</code>; MemCP does not expose a PostgreSQL wire-protocol port.
PostgreSQL SQL syntax is available over <code>/psql/&lt;database&gt;</code>; MemCP does not expose a PostgreSQL wire-protocol port.



Latest revision as of 12:14, 28 August 2026


Migration from MySQL and PostgreSQL

Migration is a compatibility and operations project, not only a data copy. MemCP can import through live MySQL/PostgreSQL connections or supported dump formats, while applications connect through the MySQL protocol or the HTTP SQL endpoints. It does not expose a PostgreSQL wire-protocol server and does not claim complete syntax, metadata, type, or administration compatibility with either source system.

Keep the source database authoritative until schema translation, row counts, constraints, representative queries, writes, timezone behavior, and restart recovery have been validated. Measure import duration and application latency with successful results, retain a rollback path, and separately design ongoing change capture when the source continues receiving writes during a staged migration.

MemCP client and import connection paths

Live import

; MySQL: host/port nil use 127.0.0.1:3306
(mysql_import nil nil "import_user" "secret" "source_db" "target_db")

; PostgreSQL: database, source schema, target database
(psql_import nil nil "postgres" "secret" "source_db" "public" "target_db")

Optional trailing arguments select or rename individual tables. Use a least-privilege read-only source account and protect credentials from shell and process listings.

Dumps

load_sql reads MySQL SQL; load_psql reads PostgreSQL SQL and supported pg_dump/archive inputs. A compressed input must be decompressed (zcat/xzcat), not passed through the gzip/xz compression functions.

gzip -dk dump.sql.gz
# Then in the MemCP console:
# (load_sql "target_db" (stream "dump.sql"))

For large or live migrations, prefer the importer functions above rather than assuming every vendor-specific dump statement is accepted.

Application connection

$db = new PDO(
    'mysql:host=127.0.0.1;port=3307;dbname=target_db',
    'root',
    'strong-password'
);
echo $db->query("SELECT 'it works'")->fetchColumn();

PostgreSQL SQL syntax is available over /psql/<database>; MemCP does not expose a PostgreSQL wire-protocol port.

Validation checklist

  • compare schemas, types, defaults, indexes, constraints, triggers, and views;
  • compare counts and checksums per table;
  • replay representative reads and writes against both systems;
  • verify AUTO_INCREMENT and timezone behavior;
  • restart MemCP and repeat checks;
  • measure import duration, query latency, errors, and CDC lag if live replication is used;
  • retain a tested rollback path until cutover gates pass.