MySQL 节点常见问题(MySQL node common issues)#
这里是一些关于 MySQL 节点 的常见错误和问题,以及解决或排查它们的步骤。
🌐 Here are some common errors and issues with the MySQL node and steps to resolve or troubleshoot them.
按复合键更新行(Update rows by composite key)#
MySQL 节点的更新操作允许你通过提供一个匹配列和一个值来更新表中的行。这适用于那些单列值可以唯一标识单行的表。
🌐 The MySQL node's Update operation lets you to update rows in a table by providing a Column to Match On and a value. This works for tables where single column values can uniquely identify individual rows.
你不能将此模式用于使用复合键的表,这类表需要多个列来唯一标识一行。一个例子是 MySQL 的 user 表 在 mysql 数据库中,其中你需要 user 和 host 两列才能唯一标识行。
🌐 You can't use this pattern for tables that use composite keys, where you need multiple columns to uniquely identify a row. A example of this is MySQL's user table in the mysql database, where you need both the user and host columns to uniquely identify rows.
要更新具有复合键的表,请改为使用 执行 SQL 操作手动编写查询。在那里,你可以匹配多个值,例如下面这个同时匹配 customer_id 和 product_id 的示例:
🌐 To update tables with composite keys, write the query manually with the Execute SQL operation instead. There, you can match on multiple values, like in this example which matches on both customer_id and product_id:
1 | |
使用 Docker 时无法连接到本地 MySQL 服务器(Can't connect to a local MySQL server when using Docker)#
运行无论在 Docker 中使用 n8n 还是 MySQL,都需要配置网络,以便 n8n 可以连接到 MySQL。
🌐 When you run either n8n or MySQL in Docker, you need to configure the network so that n8n can connect to MySQL.
解决方案取决于你如何托管这两个组件。
🌐 The solution depends on how you're hosting the two components.
如果只有 MySQL 在 Docker 容器中(If only MySQL is in Docker)#
如果只有 MySQL 在 Docker 中运行,请通过在容器内绑定到 0.0.0.0 来配置 MySQL 监听所有接口(官方镜像已经这样配置)。
🌐 If only MySQL is running in Docker, configure MySQL to listen on all interfaces by binding to 0.0.0.0 inside of the container (the official images are already configured this way).
运行容器时,使用 -p 标志发布端口。默认情况下,MySQL 运行在端口 3306,因此你的 Docker 命令应该如下所示:
🌐 When running the container, publish the port with the -p flag. By default, MySQL runs on port 3306, so your Docker command should look like this:
1 | |
在配置 MySQL 凭据 时,localhost 地址应该可以正常使用(将 Host 设置为 localhost)。
🌐 When configuring MySQL credentials, the localhost address should work without a problem (set the Host to localhost).
如果只有 n8n 在 Docker 容器中(If only n8n is in Docker)#
如果 n8n 仅在 Docker 中运行,请通过在主机上绑定到 0.0.0.0 来配置 MySQL 监听所有接口。
🌐 If only n8n is running in Docker, configure MySQL to listen on all interfaces by binding to 0.0.0.0 on the host.
如果你在 Linux 上使用 Docker 运行 n8n,在启动容器时使用 --add-host 标志将 host.docker.internal 映射到 host-gateway。例如:
🌐 If you are running n8n in Docker on Linux, use the --add-host flag to map host.docker.internal to host-gateway when you start the container. For example:
1 | |
如果你使用的是 Docker Desktop,系统会自动为你配置。
🌐 If you are using Docker Desktop, this is automatically configured for you.
在配置 MySQL 凭据 时,将 host.docker.internal 用作 主机 地址,而不是 localhost。
🌐 When configuring MySQL credentials, use host.docker.internal as the Host address instead of localhost.
如果 MySQL 和 n8n 运行在不同的 Docker 容器中容器(If MySQL and n8n are running in separate Docker containers)#
如果 n8n 和 MySQL 都运行在 Docker 的不同容器中,你可以使用 Docker 网络将它们连接起来。
🌐 If both n8n and MySQL are running in Docker in separate containers, you can use Docker networking to connect them.
通过在容器内将 MySQL 绑定到 0.0.0.0 来配置 MySQL 监听所有接口(官方镜像已经这样配置)。将 MySQL 和 n8n 容器都添加到同一个用户定义的桥接网络中。
🌐 Configure MySQL to listen on all interfaces by binding to 0.0.0.0 inside of the container (the official images are already configured this way). Add both the MySQL and n8n containers to the same user-defined bridge network.
在配置 MySQL 凭据 时,请使用 MySQL 容器的名称作为主机地址,而不是 localhost。例如,如果你将 MySQL 容器命名为 my-mysql,则应将 主机 设置为 my-mysql。
🌐 When configuring MySQL credentials, use the MySQL container's name as the host address instead of localhost. For example, if you call the MySQL container my-mysql, you would set the Host to my-mysql.
如果 MySQL 和 n8n 运行在同一个 Docker 容器中(If MySQL and n8n are running in the same Docker container)#
如果 MySQL 和 n8n 运行在同一个 Docker 容器中,localhost 地址不需要任何特殊配置。你可以配置 MySQL 监听 localhost,并在 n8n 中的 MySQL 凭据 中将 Host 配置为使用 localhost。
🌐 If MySQL and n8n are running in the same Docker container, the localhost address doesn't need any special configuration. You can configure MySQL to listen on localhost and configure the Host in the MySQL credentials in n8n to use localhost.
以字符串形式返回的十进制数(Decimal numbers returned as strings)#
默认情况下,MySQL 节点将 DECIMAL 值 当作字符串返回。这是有意为之,以避免由于 JavaScript 表示数字的方式存在限制而导致的精度丢失。你可以在 n8n 使用的 MySQL 库 的文档中了解更多关于此决策的信息。
🌐 By default, the MySQL node returns DECIMAL values as strings. This is done intentionally to avoid loss of precision that can occur due to limitation with the way JavaScript represents numbers. You can learn more about the decision in the documentation for the MySQL library that n8n uses.
要以数字而不是字符串的形式输出小数值,并忽略精度损失的风险,请启用 将小数输出为数字 选项。这样将以数字而不是字符串的形式输出值。
🌐 To output decimal values as numbers instead of strings and ignore the risks in loss of precision, enable the Output Decimals as Numbers option. This will output the values as numbers instead of strings.
作为一种替代方法,你可以使用 toFloat() 函数 配合 toFixed() 手动将字符串转换为小数,或者在 MySQL 节点之后使用 编辑字段(设置)节点。请注意,你可能仍然需要考虑潜在的精度损失。
🌐 As an alternative, you can manually convert from the string to a decimal using the toFloat() function with toFixed() or with the Edit Fields (Set) node after the MySQL node. Be aware that you may still need to account for a potential loss of precision.