my2pg - MySQL -> PostgreSQL dump conversion utility.
mysqldump db | ./my2pg.pl [-ndsht] > pgsqldump.sql
vi libtypes.c
make
psql database < pgsqldump.txt
where
- pgsqldump.sql
-
- file suitable for loading into PostgreSQL.
- libtypes.c
-
- C source for emulated MySQL types (ENUM, SET) generated by my2pg
my2pg utility attempts to convert MySQL database dump to Postgres's one.
my2pg performs such conversions:
- Type conversion.
It tries to find proper Postgres
type for each column.
Unknown types are silently pushing to output dump;
ENUM and SET types implemented via user types
(C source for such types can be found in
libtypes.c file);
- Encloses identifiers into double quotes.
All column and table
names should be enclosed to double-quotes to prevent
conflict with reserved SQL keywords;
- Converting
AUTO_INCREMENT fields to SERIAL. Actually, creating the sequence and
setting default value to nextval('seq'), well, you know :)
- Converting
KEY(field) to CREATE INDEX i_field on table (field);
- The same
for UNIQUE keys;
- Indices
are creating AFTER rows insertion (to speed up the load);
- Translates '#'
MySQL comments to ANSI SQL '--'
It encloses dump in transaction block to prevent single errors
during data load.
My2pg takes the following command-line options:
- -n
-
Convert *CHAR DEFAULT '' NOT NULL types to *CHAR NULL.
Postgres can't load empty '' strings in NOT NULL fields.
- -d
-
Add double quotes around table and column names
- -h
-
Show usage banner.
- -s
-
Do not attempt to convert data. Currently my2pg only tries to convert
date and time data.
- -t
-
Do not output row information, e.g. only output CREATE TABLE's and skip
INSERT's.
- creates
file libtypes.c in current directory
overwriting existed file without any checks;
- the same
for Makefile.
Known bugs are:
- Possible problems with the timestamp data.
PostgreSQL does not accept incorrect date/time values like 2002-00-15,
while MySQL does not care about that. Currently my2pg cannot handle this
issue. You should care yourself to convert such a data.
- Use -s option if your numeric data are broken during conversion.
My2pg attempts to convert MySQL timestamps of the form yyyymmdd to
yyyy-mm-dd and yyyymmddhhmmss to yyyy-mm-dd hh:mm:ss. It performs
some heuristic checks to ensure that the month,day,hour,minutes and seconds have
values from the correct range (0..12, 0..31, 0..23, 0..59, 0..59 respectively).
It is still possible that your numeric values that satisfy these conditions
will get broken.
- Possible problems with enclosing identifiers in double quotes.
All identifiers such as table and column names should be enclosed in double
quotes. Program can't handle upper-case identifiers,
like DBA. Lower-case identifiers are OK.
- SET type emulation is not full. LIKE operation on
SETs, raw integer input values should be implemented
- Makefile
generated during output is
platform-dependent and surely works only on
Linux/gcc (FreeBSD/gcc probably works as well - not tested)
- Generated libtypes.c contain line
#include <postgres.h>
This file may be located not in standard compiler
include path, you need to check it before compiling.
(c) 2000-2004 Maxim V. Rudensky (fonin@omnistaronline.com) (developer, maintainer)
(c) 2000 Valentine V. Danilchuk (val@nichemarketresearch.com) (original script)
Great thanks to all those people who provided feedback and make development
of this tool easier.
Jeff Waugh <jaw@ic.net>
Joakim Lemström <jocke@bytewize.com> || <buddyh19@hotmail.com>
Yunliang Yu <yu@math.duke.edu>
Brad Hilton <bhilton@vpop.net>
Arnaud Blancher <arnaud.blancher@ungi.net>
Yary Hluchan <yary@apicom.com>
Robert Klep <robert@patashnik.nl>
If you are not listed here please write to me.
BSD