【问题标题】:I get "SSL Connection Error" when trying to connect to a MySql Server from Powershell尝试从 Powershell 连接到 MySql 服务器时出现“SSL 连接错误”
【发布时间】:2021-08-26 21:18:22
【问题描述】:

我正在尝试在 powershell 脚本中连接到 MySql Server 数据库。这是我的代码:

Add-Type -Path 'C:\Program Files (x86)\MySQL\MySQL Connector Net 8.0.26\Assemblies\v4.5.2\MySql.Data.dll'

$Connection = [MySql.Data.MySqlClient.MySqlConnection]@{
    ConnectionString="server=127.0.0.1;port=3306;uid=user;pwd=password;database=example_db"
}
$Connection.Open()

$sql = New-Object MySql.Data.MySqlClient.MySqlCommand
$sql.Connection = $Connection
$sql.CommandText = 'SHOW DATABASES'
$sql.ExecuteNonQuery()
 
# Close the MySQL connection.
$Connection.Close()

我下载了 MySql 连接器驱动程序和所有,但是当我执行代码时,它得到了这个错误输出:

Exception calling "Open" with "0" argument(s): "SSL Connection error."
At C:\Users\Path\To\Code\db_con.ps1:9 char:1        
+ $Connection.Open()
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : MySqlException

我检查了服务器、用户、密码和所有检查,我可以使用其他客户端进行连接。也尝试使用其他有效的服务器和用户,但它只是抛出了同样的问题。

【问题讨论】:

  • 服务器是否启用了 SSL 连接?如果没有,请尝试将SslMode=none 添加到连接字符串。
  • 检查证书、它的存储位置、它的端口绑定(如果适用)。如果您将示例中的服务器地址替换为环回,并且您实际上是在尝试与远程计算机通信,请确保该端口在防火墙(硬件或软件)上打开。
  • @BaconBits,谢谢。这对我有用。
  • @AnotherCoder Cool 我会回答的。

标签: mysql powershell connection


【解决方案1】:

服务器是否启用了 SSL 连接?如果没有,请尝试将SslMode=none 添加到连接字符串中。

【讨论】:

    猜你喜欢
    • 2015-05-28
    • 1970-01-01
    • 2019-07-25
    • 2016-12-03
    • 1970-01-01
    • 1970-01-01
    • 2012-10-04
    • 1970-01-01
    • 2014-10-29
    相关资源
    最近更新 更多