我正在尝试将数据建模工具 (DbSchema) 连接到在 Google Cloud SQL 中运行的 MySQL 数据库。云实例需要 SSL。我已将必要的 key 下载到我的 Mac,并且可以通过某些工具进行连接,例如 Sequel Pro 和 MySQL Workbench。然而,这些工具为我提供了一种将关键位置输入到其连接窗口中的方法。但是,DbSchema 不这样做 - 它所做的只是允许我修改它用于通过 JDBC 连接到数据库的连接字符串。
到目前为止我所拥有的是:
jdbc:mysql://<MY IP ADDRESS>:3306?useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull&useOldAliasMetadataBehavior=true&useSSL=true&verifyServerCertificate=false
尽管我使用的密码是正确的,但这最终给了我一个密码错误。我认为问题是 JDBC 没有使用 SSL key 。有没有办法指定此连接字符串中 SSL key 的位置?
最佳答案
这个MySQL JDBC (for SSL) link可能会帮助你。请参阅设置客户端身份验证:
Once you have the client private key and certificate files you want to use, you need to import them into a Java keystore so that they can be used by the Java SSL library and Connector/J. The following instructions explain how to create the keystore file:
将客户端 key 和证书文件转换为 PKCS #12 存档:
shell> openssl pkcs12 -export -in client-cert.pem -inkey client-key.pem \ -name "mysqlclient" -passout pass:mypassword -out client-keystore.p12
将客户端 key 和证书导入 Java keystore :
shell> keytool -importkeystore -srckeystore client-keystore.p12 -srcstoretype pkcs12 \ -srcstorepass mypassword -destkeystore keystore -deststoretype JKS -deststorepass mypassword
设置 JDBC 连接属性:
clientCertificateKeyStoreUrl=file:path_to_truststore_file clientCertificateKeyStorePassword=mypassword
关于mysql - 使用 SSL 的 JDBC 连接到 MySQL 的命令字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50245075/