mysql connection with ssl
Hello! Is it possible to connect to a mysql server using only ssl without a password with this module?
@icabraja theoretically any known way of connecting should be supported by using the -ConnectionString parameter. the other parameter sets exist to make connecting simpler without having to formulate a connection string, but for the non-common cases, that parameter exists. There is also the -Additional parameter that allows you specify additional connection parameters while using the simpler approach.
if you can provide me a connection string example, I can provide a suggestion on how to make the connection.
Hello @mithrandyr!
Here is an example using MySQL .NET connector
$ConnectionString = "Server=$MySQLHost;Port=$MySQLPort;Uid=$MySQLUser;Database=$DatabaseName;SslMode=Required;SslCert=$CertificatePath;SslKey=$KeyPath"
$Connection = New-Object MySql.Data.MySqlClient.MySqlConnection($ConnectionString)
Regards, Ivan
Edit:
If I pass a hash table to a -Additional parameter with ssl cert, key and user i get and error:
SslCert and SslKey connection string options are not supported in netstandard2.0
Examlpe:
$ssl = @{
Uid = "ssluser"
SslCert = "C:\ssl\client-cert.pem"
SslKey = "C:\ssl\client-key.pem"
}
Open-MySqlConnection -ConnectionName "test" -Server "localhost" -Database "dashboard" -Port "3306" -SSLMode Required -Additional $ssl
I have also tried using the -ConnectionString parameter with above mentioned $ConnectionString and I get the same error.
Unfortunately I couldn't find an answer. Btw, the above mentioned $ConnectionString works with MySQL .NET connector.
Regards, Ivan
@icabraja - it looks like a limitation of the MySqlConnector library and .Net standard 2.0 implementations. https://github.com/mysql-net/MySqlConnector/blob/72ee684ed0e04e5f39d6e0757a1963e4aa36807f/src/MySqlConnector/Core/ServerSession.cs#L1516
Because I want SimplySql to work for both PS 5.1 and PS7+, I'm building against .NetStandard 2.0. I'd have to look at a different approach in order to handle this.
Hello @mithrandyr!
Thank you for the info and your effort, I apricate it.
Is there maybe a way to use ODBC driver with existing DSN or to pass DSN connection values? I have tried to pass to -ConnectionString New-Object System.Data.Odbc.OdbcConnection("DSN=mysql;") where mysql is the name of already configured DSN connection, but i get and error : Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.
Regards, Ivan
@icabraja -- -ConnectionString always is just that... a connection string -- it can't be anything else. Now you could try just passing in "DSN=mysql" though I have no idea if that will work.
@icabraja -- The next version (2.1.0, hopefully coming out soon) -- may fix the issue you are having...
Hello @mithrandyr!
Thank you for the heads-up, and thank you for the effort. Much appreciated.
@icabraja -- Version 2.1 is released, please see if your issue is resolved.