跳到主要内容 跳到补充内容

MySQL

本主题介绍如何使用 MySQL 目标连接器配置与 MySQL 目标的连接。MySQL 只能在复制任务中用作目标数据库。在连接到 MySQL 目标之前,您需要在数据库上配置 所需的权限。如果您通过 Data Movement gateway 连接到MySQL,还需要安装驱动程序设置中所述的驱动程序。

有关使用 MySQL 连接器时的限制和注意事项的信息,请参阅限制和考虑事项

设置连接属性

要配置连接器,请执行以下操作:

  1. 连接中单击创建连接

  2. 选择 MySQL 目标连接器,然后提供以下设置:

数据目标

  • 数据网关当使用 Data Movement gateway时,选择将用于测试与 MySQL 目标的连接的数据网关。这应该是用于访问数据源的同一网关。

    信息注释
    • 此字段不适用于 Qlik Talend Cloud Starter 订阅,因为此订阅层不支持 Data Movement gateway
    • 您还需要在 Data Movement gateway 计算机上安装相应的驱动程序。有关详细信息,请参阅下文的驱动程序设置

  • 云提供者:根据需要选择以下项之一:

      • 对于 MySQL 内部部署、MariaDB、Amazon Aurora 或 Microsoft Azure Database for MySQL - Flexible Server。
      • 当不使用 Data Movement gateway
    • 对于 Amazon RDS for MariaDB 或 Amazon RDS for MySQL。

    • 对于 Google Cloud SQL for MySQL。

    • 对于 Microsoft Azure Database For MySQL。

  • 服务器:安装 MySQL 数据库的计算机的主机名或 IP 地址。

  • 端口:连接到数据库时要使用的端口。默认值为 3306。

帐户属性

用户名称密码:经授权可访问 MySQL 数据库的用户的用户名和密码。

数据库属性

  • 目标数据库类型:选择以下项之一:
    • 特定数据库:选择此选项后,所有源架构都将加载到指定的数据库中。
    • 多个数据库:选择此选项后,每个源模式都将加载到其相应的数据库中。此外,默认情况下,所有控制表都将复制到一个名为 attrep_control 的新模式中。有关控制表的更多信息,请参阅控制表
  • 最大文件大小 (KB):在将 CSV 文件加载到 MySQL 目标数据库之前,选择或键入其最大大小(以 KB 为单位)。默认值为 32000 KB。
  • 平行加载线程:当将数据加载到 MySQL 目标数据库时,增加线程数量可能会提高性能。请注意,设置大量线程可能会对数据库性能产生不利影响,因为每个线程都需要单独的连接。

内部属性

内部属性用于特殊用例,因此不会在对话框中公开。只有在 Qlik 支持部门的指示下,您才应该使用它们。

使用字段右侧的 新建取消 按钮可以根据需要添加或删除特性。

名称

连接的显示名称。

先决条件

所需的权限

必须授予连接器设置中指定的用户:

  • MySQL 帐户访问权限
  • MySQL 数据库中的读/写权限
  • 复制中涉及的每个目标模式的以下权限:
    • ALTER
    • 创建
    • CREATE TEMPORARY TABLES
    • DELETE
    • DROP
    • INSERT
    • SELECT
    • UPDATE

驱动程序设置

本部分介绍如何安装所需的 driver。这个过程包括运行一个脚本,该脚本将自动下载、安装和配置所需的 driver。您还可以根据需要运行脚本来更新和卸载 driver

  • 请确保在 Data Movement 网关服务器上安装了 Python 3.6 或更高版本。

    Python 预装在大多数 Linux 发行版上。您可以通过运行以下命令来检查系统上安装了哪个 Python 版本。

    python3 --version

下载并安装 driver

  1. Data Movement 网关计算机上,将工作目录更改为:

    opt/qlik/gateway/movement/drivers/bin

  2. 然后运行以下命令:

    语法:

    ./install mysql

    如果无法下载 driver(由于访问限制或技术问题),将显示一条消息,为您指示在 Data Movement 网关机器上下载 driver 的位置和复制驱动程序的位置。完成此操作后,请再次运行 install mysql 命令。

    否则,将显示 driver 的 EULA。

  3. 执行以下操作之一:

    • 重复按 [Enter] 可在 EULA 中缓慢滚动。
    • 重复按空格键可快速滚动 EULA。
    • 按 q 退出许可证文本并显示 EULA 接受选项。
  4. 执行以下操作之一:

    • 键入 "y" 并按 [Enter] 接受 EULA 并开始安装。
    • 键入 "n" 并按 [Enter] 拒绝 EULA 并退出安装。
    • 键入“v”并按 [Enter] 以再次查看 EULA。

  5. 将会安装 driver

如果要在安装提供的 driver 之前卸载以前版本的 driver,请运行 update 命令。

下载并更新 driver

  1. Data Movement 网关计算机上,将工作目录更改为:

    opt/qlik/gateway/movement/drivers/bin

  2. 然后运行以下命令:

    语法:

    ./update mysql

    如果无法下载 driver(由于访问限制或技术问题),将显示一条消息,为您指示在 Data Movement 网关机器上下载 driver 的位置和复制驱动程序的位置。完成此操作后,请再次运行 update mysql 命令。

    否则,将显示 driver 的 EULA。

  3. 执行以下操作之一:

    • 重复按 [Enter] 可在 EULA 中缓慢滚动。
    • 重复按空格键可快速滚动 EULA。
    • 按 q 退出许可证文本并显示 EULA 接受选项。
  4. 执行以下操作之一:

    • 键入 "y" 并按 [Enter] 接受 EULA 并开始安装。
    • 键入 "n" 并按 [Enter] 拒绝 EULA 并退出安装。
    • 键入“v”并按 [Enter] 可从头开始查看 EULA。
  5. 将卸载旧的 driver,并安装新的 driver

如果要卸载 driver,请运行 uninstall 命令。

卸载 driver

  1. 停止所有配置为使用此连接器的任务。

  2. Data Movement 网关计算机上,将工作目录更改为:

    opt/qlik/gateway/movement/drivers/bin

  3. 然后运行以下命令:

    语法:

    ./uninstall mysql

    将卸载 driver

手动安装驱动程序

只有在自动驱动程序安装未成功完成的情况下,才应尝试手动安装 driver

安装 Data Movement gateway 后,下载 mysql-connector-odbc-<版本>.x86_64.rpm 驱动程序。您可以在此路径下面找到受支持版本的直接下载链接:binary-artifacts in /opt/qlik/gateway/movement/drivers/manifests/mysql.yaml。下载完成后,将 RPM 复制到 Data Movement gateway 机器上。

数据移动网关 服务器上,打开 shell 提示符并执行以下操作:

  1. 停止 数据移动网关 服务:

    sudo systemctl stop repagent

  2. 可选择确认服务已停止:

    sudo systemctl status repagent

    状态应如下所示:

    Active: inactive (dead) since <timestamp> ago

  3. 数据移动网关 计算机上安装驱动程序。
  4. 将工作目录更改为 <数据移动网关_Install_Dir>/bin.

  5. 将驱动程序位置复制到 site_arep_login.sh 文件:

    echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/lib64" >> site_arep_login.sh

    这将把驱动程序添加到 "LD_LIBRARY_PATH" 并更新 site_arep_login.sh 文件中的驱动程序位置。

  6. 可选择确认已将驱动程序位置复制:

    cat site_arep_login.sh
  7. 确保 /etc/odbcinst.ini 文件包含 MySQL 的条目,如以下示例所示:

    [MySQL ODBC 8.0 Unicode Driver]

    Driver = /usr/lib64/libmyodbc8w.so

    UsageCount = 1

  8. 启动 数据移动网关 服务:

    sudo systemctl start repagent

  9. 可选择确认服务已启动:

    sudo systemctl status repagent

    状态应如下所示:

    Active: active (running) since <timestamp> ago

限制和考虑事项

当使用 MySQL 作为复制目标时,以下限制适用:

  • When replicating to the MariaDB target database, if the DATETIME value is set to zero, you need to define a transformation that replaces the DATETIME with valid values. For example:

    replace($datetime_column,'9999-12-31 23:59:59','2000-01-01 22:00:00')

    信息注释This limitation does not apply to Microsoft Azure Database for MySQL.
  • Due to the way MySQL operates, when loading data to a MySQL target during a Full Load task, duplicate key errors will not be reported to the logs.
  • When updating a column's value to its existing value, a zero rows affected is returned from MySQL (unlike Oracle and Microsoft SQL Server that perform an update of one row).

    This generates an entry in the attrep_apply_exceptions Control Table and the following warning:

    Some changes from the source database had no impact when applied to the target database. See attrep_apply_exceptions table for details.

  • Due to an issue with MySQL 5.7 (which was resolved in version 8.0), multibyte characters cannot be inserted into TEXT columns when the Full Load uses CSV files. Consequently, if the target endpoint is MySQL 5.7 and a replicated table contains TEXT columns with UTF-8 multibyte characters, the target table might be empty.

     

    Workaround:

    In the connector settings, set the loadUsingCSV internal parameter to FALSE. Note that this might impact performance.

  • If you need to replicate 4-byte emoji characters, the target schema character set must be set to utf8mb4.

数据类型

本机数据类型信息将被保留,并显示在数据集视图的本机数据类型列中。如果列不可见,则需要打开数据集视图的列选择器,然后选择本机数据类型列。

Supported data types
Qlik Cloud data types MySQL data types

BOOL

BOOL

BYTES

If length is => 1 and =< 8095, then:

VARBINARY (Length)

If length is => 8096 and =< 65535, then:

BLOB

If length is => 65536 and =< 16777215, then:

MEDIUMBLOB

If length is => 16777216 and =< 2147483647, then:

LONGBLOB

DATE

DATE

TIME

TIME

DATETIME

If scale is => 0 and =< 6, then:

DECIMAL (p,s)

If scale is => 7 and =< 12, then:

VARCHAR (37)

INT1

TINYINT

INT2

SMALLINT

INT4

INTEGER

INT8

BIGINT

NUMERIC

If scale is => 0 and =< 30, then:

DECIMAL (p,s)

If scale is => 31 and =< 100, then:

VARCHAR (45)

REAL4

FLOAT

REAL8

DOUBLE

STRING

If length is => 1 and =< 8095, then:

VARCHAR (Length)

If length is => 8096 and =< 65535, then:

TEXT

If length is => 65536 and =< 16777215, then:

MEDIUMTEXT

If length is => 16777216 and =< 2147483647, then:

LONGTEXT

UINT1

UNSIGNED TINYINT

UINT2

UNSIGNED SMALLINT

UINT4

UNSIGNED INTEGER

UINT8

UNSIGNED BIGINT

WSTRING

If length is => 1 and =< 8095, then:

VARCHAR (Length)

If length is => 8096 and =< 65535, then:

TEXT

If length is => 65536 and =< 16777215, then:

MEDIUMTEXT

If length is => 16777216 and =< 2147483647, then:

LONGTEXT

BLOB

When the Allow unlimited LOB size option is enabled:

  • LONGBLOB

When the Limit LOB size to option is enabled:

  • If the specified value i is 63 KB or smaller, then:

    BLOB

  • If the specified value is 64 KB or larger, then:

    LONGBLOB

For information on limiting LOB size, see Metadata.

NCLOB

When the Allow unlimited LOB size option is enabled:

  • TEXT

When the Limit LOB size to option is enabled:

  • If the specified value is 63 KB or smaller, then:

    TEXT

  • If the specified value is 64 KB or larger, then:

    LONGTEXT

For information on limiting LOB size, see Metadata.

CLOB

When the Allow unlimited LOB size option is enabled:

  • TEXT CHARACTER SET UTF-16

When the Limit LOB size to option is enabled:

  • If the specified value is 63 KB or smaller, then:

    TEXT CHARACTER SET UTF-16

  • If the specified value is 64 KB or larger, then:

    LONGTEXT CHARACTER SET UTF-16

For information on limiting LOB size, see Metadata.

本页面有帮助吗?

如果您发现此页面或其内容有任何问题 – 打字错误、遗漏步骤或技术错误 – 请告诉我们如何改进!