【问题标题】:AWS Glue - Unable to connect to mysqlAWS Glue - 无法连接到 mysql
【发布时间】:2019-05-21 14:41:35
【问题描述】:

嗨,在此实例中,数据库安全组对所有入站流量(所有端口 - 所有来源)开放。

我还可以在 mysql workbench 或 Datagrip 中很好地连接到数据库,这肯定使用 jdbc 连接字符串。

2019-05-21 14:12:03 INFO CatalogClient:651 - Got connection 'tem-sas-main' info from Catalog with url: jdbc:mysql://my-database-example:3306/sas_tem_central
2019-05-21 14:12:03 INFO CatalogClient:684 - JDBC configuration for connection tem-sas-main: JDBCConfiguration(url=jdbc:mysql://my-database-example:3306/sas_tem_central, hostname=my-database-example, port=3306, databaseVendor=mysql, databaseVersion=null, connectionName=tem-sas-main, path=sas_tem_central, subnetId=subnet-0717c4db096e84393, availabilityZone=eu-west-1a, securityGroups=[sg-074b074ebc51c2315], enforceSSL=false)
2019-05-21 14:12:03 INFO JdbcConnection:42 - Starting connecter. driver com.mysql.jdbc.Driver@7e5d9a50
2019-05-21 14:12:03 INFO JdbcConnection:60 - Attempting to connect with SSL host matching: jdbc:mysql://my-database-example:3306/sas_tem_central
2019-05-21 14:14:15 INFO JdbcConnection:69 - SSL connection to data store using host matching failed. Retrying without host matching.
2019-05-21 14:14:15 INFO JdbcConnection:83 - Attempting to connect with SSL: jdbc:mysql://my-database-example:3306/sas_tem_central
2019-05-21 14:16:26 INFO JdbcConnection:88 - SSL connection to data store failed. Retrying without SSL.
2019-05-21 14:16:26 INFO JdbcConnection:102 - Attempting to connect without SSL: jdbc:mysql://my-database-example:3306/sas_tem_central
Check that your connection definition references your JDBC database with correct URL syntax, username, and password. Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

还要注意我的 JDBC 连接字符串是

jdbc:mysql://my-database-example:3306/sas_tem_central

并且要求 SSL 连接设置为 false

【问题讨论】:

  • 您的 MySQL 实例是否通过 SSL 保护?如果是这样,那么您需要使用来自公认的公共证书颁发机构的证书:docs.aws.amazon.com/quicksight/latest/user/…
  • 你是如何尝试用胶水连接的。请提供一些代码sn-p。
  • @HarshBafna 我正在尝试通过 JDBC 连接进行连接,我的连接字符串是“jdbc:mysql://my-database-example:3306/sas_tem_central” - 还需要 SSL 连接为 false
  • 我假设您提供了一些用于在胶水 etl 中连接到 MySQL 的 spark 代码。你能分享一下你正在做的事情吗?
  • @FaizRasool :您是否在粘合连接中配置与附加到 RDS 实例的 VPC/安全组相同的 VPC/安全组。

标签: mysql amazon-web-services jdbc aws-glue


【解决方案1】:

在与 AWS 架构师交谈后,我可以确认 Glue 目前不适用于 MySql 版本 8。这在我能找到的任何地方都没有记录。

【讨论】:

  • 那么您可以将其设置为您问题的答案
  • 您可以使用自己的 JDBC 驱动程序和一些配置使其与例如MySQL 8,见stackoverflow.com/a/64178019/878612 当然这不是开箱即用的,它需要一些配置。
【解决方案2】:

Glue's supported Databases(未在 Glue 文档/常见问题解答中突出显示)

下表列出了 AWS Glue 支持的 JDBC 驱动程序版本。

Microsoft SQL Server    6.x
MySQL   5.1
Oracle Database 11.2
PostgreSQL  42.x
Amazon Redshift 4.1

现在您可以customize your own configuration 从 AWS Glue 作业连接到 MySQL 8 和其他更新的数据库。

  1. 下载 MySQL 8 的 JDBC 驱动程序
  2. 上传到 S3
  3. 通过 Glue - Tables - Connections 创建到数据库的 JDBC 连接 (请注意,这将无法使用“测试连接”,因为支持的最新版本是(当前)5.7
  4. 编辑 Glue 作业 - 依赖 jar 路径 - 例如 s3://yourS3bucket/path/mysql-connector-java-8.0.21.jar
  5. 修改胶水作业,例如Python 脚本
datasink4 = glueContext.write_dynamic_frame.from_jdbc_conf
(frame = dropnullfields3, catalog_connection = “GLUE-CONNECTION-NAME”, 
connection_options = { 
"customJdbcDriverS3Path": "s3://yourS3Bucket/path/mysql-connector-java-8.0.21.jar", 
"customJdbcDriverClassName": "com.mysql.cj.jdbc.Driver", 
"user": “#DBuserName#”, "password": “DbUsersPassword”, 
"url":"jdbc:mysql://dbname.url.region.rds.amazonaws.com/schemaName, 
"connectionType": "mysql", "dbtable": “tablenameInDb”, 
"database": “schemaName”}, transformation_ctx = "datasink4")

(该脚本中没有新行)

【讨论】:

    【解决方案3】:

    您的连接字符串看起来正确。

    我在同样的问题上苦苦挣扎,发现我必须解决一些问题:

    1. 确保您用于 RDS 的安全组是自引用的。这意味着您应该将来自 RDS 上的数据库实例的安全组添加到所有 TCP 的入站和出站规则中。

    2. 确保您已为您的 VPC 创建了终端节点。为此,导航到您的 VPC,单击“端点”,为 RDS 所在的 VPC 添加一个“端点”,然后为 S3 创建一个端点。

    3. 最后,您创建 MySQL RDS 实例的版本应该是版本 5(而不是版本 8)。我注意到 AWS Glue JDBC 连接器仅适用于 MySQL 版本 5 (5.7)

    【讨论】:

      【解决方案4】:

      当您将 AWS RDS 与 MySQL 引擎一起使用时,您无需创建 JDBC 连接。您可以在创建连接时使用 Amazon RDS。

      New Connection Screen

      【讨论】:

      • 即使您选择 Amazon RDS,它仍然会生成 jdbc 字符串作为连接 URI。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-13
      相关资源
      最近更新 更多