I am trying to work in a connection to a MySql Server database in a powershell script. This is my code:
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()
I downloaded the MySql Connector driver and all, but when I execute the code it gets this error output:
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
I checked the server, user, pwd and everything checks, I can connect using other clients. Also tried using other valid servers and users, but it just throws this same problem.
Does the server have SSL connections enabled? If not, try adding SslMode=none
to the connection string.