A
A
Andrey Strelkov2020-04-30 11:00:23
MySQL
Andrey Strelkov, 2020-04-30 11:00:23

How to connect to MySQL through Powershell 2.0?

Good afternoon, I'm trying to connect using Powershell (2.0) to MySQL (I use the dll file from the version under NetFramework 2.0, because connections will be made from computers where powershell 2.0)

[void][System.Reflection.Assembly]::LoadFrom("С:\temp\MySql.Data.dll")

$connection=New-Object MySql.Data.MySqlClient.MySqlConnection
$connection.ConnectionString="server=database_hostname;user=user_name;password=user_password;database=database_name"

$connection.Open()
$connection.Close()


But when I try to open a connection, I get an error

PS C:\Users\strelkov.av> C:\Users\strelkov.av\Desktop\mysql.ps1
Исключение при чтении "formatValueList" : "Microsoft.PowerShell.Commands.Internal.Format.FreeFormatEntry.formatValueList"
    + CategoryInfo          : NotSpecified: (:) [out-lineoutput], GetValueInvocationException
    + FullyQualifiedErrorId : CatchFromBaseAdapterGetValue,Microsoft.PowerShell.Commands.OutLineOutputCommand


I tried to do the same thing in powershell 4 - everything works successfully.

What can the 2nd person not like when opening a connection?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
azarij, 2020-04-30
@azarij

They write that this happens when the downloaded dll'ka is located somewhere on the network, and not on the local disk.
at you c:\temp a case not on a network is mounted?
also make sure the dll is unlocked. right click on the dll file, properties and at the bottom of the properties look for unblock / unblock.

R
Roman Bezrukov, 2020-04-30
@NortheR73

And if you take the native MySQL connector? ( examples )

F
FanatPHP, 2020-04-30
@FanatPHP

mysql -h database_hostname -u user_name -puser_password database_name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question