Migrate MySQL to PostgreSQL
Move an Umami v2 MySQL database to PostgreSQL before upgrading to v3, using either a MySQL dump file or CSV exports imported with psql.
As part of Umami v3, we are removing MySQL as a supported database option and standardizing on PostgreSQL. This change ensures a more consistent and scalable data layer across all environments.
Data migration#
This document outlines the migration process from MySQL to PostgreSQL, including:
- Preparing a MySQL dump file or CSVs.
- Verifying data integrity and application compatibility.
The goal is to make the transition seamless, while preserving all data and ensuring minimal downtime. There are open-source tools like
pgloader and pg_chameleon that you may explore. The process outlined below is a pure data migration into a new v2 PostgreSQL database,
making this method as simple and agnostic as possible.
Requirements#
- MySQL database schema must be in sync with the latest v2 version (v2.19.0).
- Credentials to both databases:
Install Umami with a PostgreSQL database#
- Install Umami (v2.19.0) on a PostgreSQL server. Documentation for the installation process can be found here.
- Truncate the tables below. These tables will be populated from the MySQL import.
Running migration#
MySQL dump file#
For smaller databases (less than 1 million records) you can use a MySQL dump file. Official docs can be found here.
- Generate a MySQL dump file.
- Replace backticks with double quotes to make it PostgreSQL compatible.
- Run the dump file using psql.
Docker version:
Now you can upgrade to Umami (v3.0).
Generating CSVs#
For larger databases, the dump file may be too large and the insert statement may become inefficient.
- Generate MySQL CSVs for all the necessary tables with data.
Inside the MySQL shell:
- The file path (/tmp/website_event.csv) is on the MySQL server's filesystem, not necessarily your host.
- Make sure MySQL has permission to write there (secure_file_priv may restrict this).
-
Move the file from the MySQL server to a location accessible by psql using
scporcp. -
Use psql
\COPYcommand to import the CSVs into the PostgreSQL database. Repeat the command for each table.
- Include the schema if you are not using the default schema.
ESCAPE '\'matches MySQL's backslash escaping (ESCAPED BY '\\'), so quotes and backslashes inside values are imported correctly.NULL '\N'matches how MySQL writesNULLvalues.