mysql - 物化 View 的数据库从 MariaDB 迁移到 PostgreSQL

标签 mysql postgresql unicode database-migration materialized-views

我的公司一直在使用 MariaDB。 MariaDB 的问题是不支持物化 View 。虽然Flexviews支持物化 View ,但它存在如下问题。 当文件“b_table.sql”的 View 定义为

Create table matered_view AS
Select timestampdiff(YEAR,`m`.`birthday`,curdate()) AS `age`
From `transDB`.`members` `m` ...

Flexviews的实用程序(convert.php)可以按如下方式使用。

$ php convert.php transDB < b_table.sql > mem_mv.sql

但是,在mem_mv.sql中你会发现

CALL  flexviews.add_expr(@mvid, 'COLUMN', 'timestampdiff(YEAR,m.birthday,curdate )', 'age');

这里检查'curdate',它应该是“curdate()”。 它还存在许多我发现极难解决的其他问题。

因此,为了将我们的 DBMS 从 MariaDB 迁移到更好地支持物化 View 的 PostgreSQL,我采用了两步过程,其中第 1 步是将 MariaDB 实例恢复到 MySQL DBMS,第 2 步是使用此模块转换 MySQL到 PostgreSQL -

philipsoutham/py-mysql2pgsql

但是,在第二步中,当我在 guest 操作系统 Ubuntu 16_4 上执行以下命令时,我遇到了此错误 -

UnicodeEncodeError: 'ascii' codec can't encode character u'\ub144' in position 60: ordinal not in range(128).

迁移过程在中间中断了——在 PostgreSQL 端仍然成功创建了一些表。实际上,MariaDB 中的表列描述/注释使用了韩文字符,这可能导致了错误。有人对我的问题有建议吗?

最佳答案

我的问题完全解决了。

也就是说, 针对“UnicodeEncodeError: 'ascii'编解码器无法编码”问题,我在相关的python源文件中嵌入了这3行代码。

import sys 
reload(sys) 
sys.setdefaultencoding('utf-8')

当我达到上述解决方案时,我在 github 上提到了以下问题(特别是 elkan1788 的评论)。

https://github.com/apache/incubator-superset/issues/2771

克服障碍后,我遇到了另一种类型的问题“UnicodeEncodeError: 'latin-1' codec can't Encode character...ordinal not in range(256)”。通过更改 mysql2pgsql 目录中的 postgres_writer.py 的一部分来解决,如下所示。

comments.append('COMMENT ON TABLE %s is %s;' % (table.name, 
QuotedString(table.comment).getquoted()))

==>

comments.append('COMMENT ON TABLE %s is %s;' % (table.name, 
QuotedString(table.comment.encode('utf-8')).getquoted()))

当我这样做时,我引用了 Lukasa 对此问题的评论 -

https://github.com/requests/requests/issues/1822

然后,我最终能够通过一个命令(py-mysql2pgsql)将 40 个 MariaDB 表迁移到 PostgreSQL 表。

关于mysql - 物化 View 的数据库从 MariaDB 迁移到 PostgreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48180705/

相关文章:

mysql - SQL 中 IMPLICIT JOIN 的目的是什么?

java - Hibernate使用PostgreSQL序列不影响序列表

mysql - sql 查询,在 where 类中进行行比较

c++ - 如何强制 Visual Studio 使用 wmain 而不是 main

mysql查询表中的高值

php和mysql不显示数据,不进入foreach循环

php - 截断字段 Php 的输出

sql - 无法计算用于较大 PostgreSQL 查询输出列的 CTE 子查询输出之间的差异

c++ - 检查UTF-8是wchar_t还是char?

php - 在桌面浏览器上正确渲染表情符号