PostgreSQL → MySQL
Convert PostgreSQL serial and identity columns to MySQL
Sequences don't exist in MySQL; auto-numbering belongs to the column itself. serial, bigserial and GENERATED … AS IDENTITY all become AUTO_INCREMENT.
serial / identity → AUTO_INCREMENT
What to know
- The AUTO_INCREMENT counter is set to max(id)+1 so inserts continue seamlessly
- Only single-column integer primary keys can be AUTO_INCREMENT in MySQL
- RETURNING id becomes LAST_INSERT_ID() (or the driver's insert id)
- Standalone sequences used by multiple tables need application-side rework
Before / after
PostgreSQL
CREATE TABLE posts (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY
); MySQL
CREATE TABLE posts (
id BIGINT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id)
) AUTO_INCREMENT=12345; Don't convert column-by-column — convert the whole database.
Upload a dump, get back ready-to-import SQL with this mapping (and every other one) applied.
Open the PostgreSQL → MySQL converterSee the full type mapping table or all guides.