首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >导出MySQL数据库并将其导入到PostgreSQL数据库

导出MySQL数据库并将其导入到PostgreSQL数据库
EN

Stack Overflow用户
提问于 2016-06-16 00:17:11
回答 1查看 933关注 0票数 0

我正在尝试导出MySQL数据库并将其导入到PostgreSQL数据库。

我试过了

使用此mysql-postgresql-converter python脚本

我有一个PHP脚本

代码语言:javascript
复制
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);

结果

我创建了2个文件

1- local.mysql 2- local.psql

只要我跑起来

代码语言:javascript
复制
psql  -U bheng  -d portal -f local.psql

我得到了

代码语言:javascript
复制
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

任何关于这方面的提示/建议都将不胜感激!

EN

回答 1

Stack Overflow用户

发布于 2018-06-16 23:47:48

您可以使用pgloader。

代码语言:javascript
复制
sudo apt-get install pgloader

使用:

pgloader mysql://user:pass@host/database postgresql://user:pass@host/database

示例:

代码语言:javascript
复制
pgloader mysql://root:root@127.0.0.1:3306/mydbinmysql postgresql://postgres:postgres@localhost:5432/mydbexportedonpgsql

只需在postgres中预先创建您想要导出到的新数据库。在上面的示例中,mydbexportedonpgsql。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37840723

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档