Which driver should I install so that mysqlcommand can start using powershell?

I installed mysqlconnector [ODBC] 5.1.8 to start my mysqlcommand, but I got this error:

Cannot find type [MySql.Data.MySqlClient.MySqlConnection]: make sure the assembly containing this type is loaded 

Which driver should I install from the mysql connector site to run this command (or any MySql command) in powershell?

I have the latest version of MySql installed on my system, and all projects work very well with MySql.

+4
source share
3 answers

You must install Connector / Net, it installs itself in the GAC and is available like any other .Net assembly.

Then you can do, for example.

 [void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data") $connectionString = "server=myserver;uid=myuser;pwd=mypass;database=mydb;" $connection = New-Object MySql.Data.MySqlClient.MySqlConnection $connection.ConnectionString = $connectionString $connection.Open() $sql = "show tables" $command = New-Object MySql.Data.MySqlClient.MySqlCommand($sql, $connection) $dataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($command) $table = New-Object System.Data.DataTable $recordCount = $dataAdapter.Fill($table) echo $table echo $table | ogv 
+1
source

For those who get this error running Powershell 2.0 and using .NET 4, the procedure is slightly different. You will still need the .NET connector.

You will need to create a configuration file in the $pshome directory to enable Powershell to work with .NET assemblies 4. This answer provides an appropriate solution for this, and the comments contain some useful information for 64-bit machines.

If you are having problems with LoadWithPartialName ... it turns out that it is deprecated from Powershell 3.0 . This alternative will work in both 2 and 3, and it may be a little easier to fix the problem, since this is a cmdlet:

 Add-Type -Path '$path\MySql.Data.dll' 

Where $ path is the directory where MySql.Data.dll is located.

0
source

place this file MySql.Data.dll in the directory where the powershell.exe file is located.

0
source

Source: https://habr.com/ru/post/1341407/


All Articles