I'm trying to export MySQL database and import it to PostgreSQL database.
using this mysql-postgresql-converter python script
if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'America/New_York');
}
//Configuration
$db = 'local';
$username = 'root';
$hostname = '127.0.0.1';
$password = '';
$date = date('Y-m-d');
$export_type = 'mysql'; // option : mysql | psql
$file_name = $date.'-portal';
$file_path = $file_name;
if($export_type == 'mysql'){
// MySQL Export
$cmd = 'mysqldump --compatible=postgresql --default-character-set=utf8 -r '.$db.'.mysql -u root '.$db;
echo $cmd. PHP_EOL;
exec($cmd);
}
// Convert
$import = 'python db_converter.py '.$db.'.mysql '.$db.'.psql';
echo $import. PHP_EOL;
exec($import);
//Import to PostSQL
$import = 'psql -U bheng -d portal -f '.$db.'.psql';
echo $import. PHP_EOL;
exec($import);
I got 2 files created
1- local.mysql 2- local.psql
As soon as I run
psql -U bheng -d portal -f local.psql
I get
psql:local.psql:12: ERROR: relation "caches" already exists
psql:local.psql:14: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:52: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:54: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:63: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:65: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:78: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:80: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:92: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:94: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:110: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:112: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:116: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:118: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:131: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:133: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:144: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:146: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:158: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:160: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:179: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:181: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:195: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:197: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:247: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:249: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:256: ERROR: cannot cast type smallint to boolean
LINE 1: ...LT, ALTER COLUMN "sign_enable" TYPE boolean USING CAST("sign...
^
psql:local.psql:257: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:258: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:263: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:264: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:265: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:266: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:267: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:268: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:269: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:270: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:271: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:272: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:273: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:274: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:275: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:276: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:277: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:278: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:279: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:280: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:281: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:282: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:283: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:284: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:285: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:286: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:287: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:288: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:289: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:290: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:291: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:292: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:293: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:294: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:local.psql:295: ERROR: current transaction is aborted, commands ignored until end of transaction block
Any hints / suggestions on this will be much appreciated !
You can use pgloader.
sudo apt-get install pgloader
Using:
pgloader mysql://user:pass@host/database postgresql://user:pass@host/database
Example:
pgloader mysql://root:root@127.0.0.1:3306/mydbinmysql postgresql://postgres:postgres@localhost:5432/mydbexportedonpgsql
Just create the new db to which you want to export to in postgres beforehand. In the example above mydbexportedonpgsql.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.