Я не могу подключиться к linux mysql контейнеру с Ubuntu на моей локальной машине. Я использую PowerShell для создания mysql соединения. Совершенно новый для работы с базами данных и ввода данных, поэтому на самом деле не знаю, что я делаю.
В контейнере я создал БД
mysql> CREATE DATABASE mydb;
Query OK, 1 row affected (0.04 sec)
mysql> CREATE TABLE test (id INT, text varchar(50), date_val date, date_time datetime);
mysql> USE mydb;
Database changed
mysql> CREATE TABLE test (id INT, text varchar(50), date_val date, date_time datetime);
Query OK, 0 rows affected (0.12 sec)
Тестирование соединения с порт, для которого был настроен контейнер с моего локального хоста
PS C:\Users\me> Test-NetConnection 127.0.0.1 -Port 3306
ComputerName : 127.0.0.1
RemoteAddress : 127.0.0.1
RemotePort : 3306
InterfaceAlias : Loopback Pseudo-Interface 1
SourceAddress : 127.0.0.1
TcpTestSucceeded : True
Вот мой скрипт powershell
[void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data")
$constr = "server=127.0.0.1:3306;port=3306;database=mydb;user id=root;password=P@ssw0rd"
$con = New-Object MySql.Data.MySqlclient.MySqlConnection
$con.ConnectionString = $constr
$con.Open()
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand
$cmd.CommandText = "INSERT INTO test VALUES(@id, @text, @date, @datetime)"
$cmd.Connection = $con
$cmd.Prepare()
$today = get-date
$cmd.Parameters("@id").Value = 1
$cmd.Parameters("@text").Value = "Text Value"
$cmd.Parameters("@date").Value = $today
$cmd.Parameters("@datetime").Value = $today
$cmd.ExecuteNonQuery()
$con.close()
Это ошибка, которую я получаю
Exception calling "Open" with "0" argument(s): "Unable to connect to any of the specified MySQL hosts."
At \\file\Tech\Dietrich\powershell scripts\VMware\Horizonview_session_count.ps1:24 char:1
+ $con.Open()
+ ~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : MySqlException
Exception calling "Prepare" with "0" argument(s): "The connection is not open."
At \\file\Tech\me\powershell scripts\VMware\Horizonview_session_count.ps1:28 char:1
+ $cmd.Prepare()
+ ~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : InvalidOperationException
Method invocation failed because [MySql.Data.MySqlClient.MySqlCommand] does not contain a method named 'Parameters'.
At \\file\Tech\me\powershell scripts\VMware\Horizonview_session_count.ps1:30 char:1
+ $cmd.Parameters("@id").Value = 1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [MySql.Data.MySqlClient.MySqlCommand] does not contain a method named 'Parameters'.
At \\file\Tech\me\powershell scripts\VMware\Horizonview_session_count.ps1:31 char:1
+ $cmd.Parameters("@text").Value = "Text Value"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [MySql.Data.MySqlClient.MySqlCommand] does not contain a method named 'Parameters'.
At \\file\Tech\me\powershell scripts\VMware\Horizonview_session_count.ps1:32 char:1
+ $cmd.Parameters("@date").Value = $today
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [MySql.Data.MySqlClient.MySqlCommand] does not contain a method named 'Parameters'.
At \\file\Tech\me\powershell scripts\VMware\Horizonview_session_count.ps1:33 char:1
+ $cmd.Parameters("@datetime").Value = $today
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Exception calling "ExecuteNonQuery" with "0" argument(s): "Connection must be valid and open."
At \\file\Tech\me\powershell scripts\VMware\Horizonview_session_count.ps1:34 char:1
+ $cmd.ExecuteNonQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : InvalidOperationException