- 安装MySQLCmdlets模块
PS /Users/sixdog/Documents/PowerShell> Install-Module MySQLCmdlets
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the
Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): y
PS /Users/sixdog/Documents/PowerShell>
- 确认已安装的MySQLCmdlets
PS /Users/sixdog/Documents/PowerShell> Get-InstalledModule
Version Name Repository Description
------- ---- ---------- -----------
23.0.8565.1 MySQLCmdlets PSGallery CData Cmdlets for MySQL
PS /Users/sixdog/Documents/PowerShell>
- 连接MySQL,并做查询
$username = 'root'
$password = '123456'
$schema = 'test'
$ip = '192.168.0.8'
$port = '3307'
$mysql = Connect-MySQL -User "$username" -Password "$password" -Database "$schema" -Server "$ip" -Port "$port"
$id = "2"
$user = Select-MySQL -Connection $mysql -Table "User" -Where "id = `'$id`'"
$user
- 报错
PS /Users/sixdog/Documents/PowerShell> ./test.ps1
Connect-MySQL: /Users/sixdog/Documents/PowerShell/test.ps1:6:10
Line |
6 | $mysql = Connect-MySQL -User "$username" -Password "$password" -Data …
| ~~~~~~~~~~~~~
| The term 'Connect-MySQL' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name,
| or if a path was included, verify that the path is correct and try again.
Select-MySQL: /Users/sixdog/Documents/PowerShell/test.ps1:9:11
Line |
9 | $orders = Select-MySQL -Connection $mysql -Table "User" -Where "id = …
| ~~~~~~~~~~~~
| The term 'Select-MySQL' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name,
| or if a path was included, verify that the path is correct and try again.
- 发现Get-Module和Get-InstalledModule的不同
51 Get-Module文档里解释:列出当前会话中导入或可从 PSModulePath 导入的模块。
5.2Get-InstalledModule文档里解释:获取 PowerShellGet 安装的计算机上的模块列表
5.3执行命令发现MySQLCmdlets不在当前会话中
PS /Users/sixdog/Documents/PowerShell> Get-Module
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Manifest 1.2.5 Microsoft.PowerShell.Archive {Compress-Archive, Expand-Archive}
Manifest 7.0.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty…}
Manifest 7.0.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object…}
Script 1.4.8.1 PackageManagement {Find-Package, Find-PackageProvider, Get-Package, Get-PackageProvider…}
Script 0.2.0 PowerShellEditorServices.Commands {Clear-Host, ConvertFrom-ScriptExtent, ConvertTo-ScriptExtent, Find-Ast…}
Binary 0.2.0 PowerShellEditorServices.VSCode {Close-VSCodeHtmlContentView, New-VSCodeHtmlContentView, Set-VSCodeHtmlContentVi…
Script 2.2.5 PowerShellGet {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability…}
Script 2.2.6 PSReadLine {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Se…
PS /Users/sixdog/Documents/PowerShell> Get-InstalledModule
Version Name Repository Description
------- ---- ---------- -----------
23.0.8565.1 MySQLCmdlets PSGallery CData Cmdlets for MySQL
6.将MySQLCmdlets引入会话中
PS /Users/sixdog/Documents/PowerShell> Import-Module MySQLCmdlets
PS /Users/sixdog/Documents/PowerShell> Get-Module
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Manifest 1.2.5 Microsoft.PowerShell.Archive {Compress-Archive, Expand-Archive}
Manifest 7.0.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty…}
Manifest 7.0.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object…}
Script 23.0.8565… MySQLCmdlets {Add-MySQL, Connect-MySQL, Disconnect-MySQL, Get-License…}
Script 1.4.8.1 PackageManagement {Find-Package, Find-PackageProvider, Get-Package, Get-PackageProvider…}
Script 0.2.0 PowerShellEditorServices.Commands {Clear-Host, ConvertFrom-ScriptExtent, ConvertTo-ScriptExtent, Find-Ast…}
Binary 0.2.0 PowerShellEditorServices.VSCode {Close-VSCodeHtmlContentView, New-VSCodeHtmlContentView, Set-VSCodeHtmlContentVi…
Script 2.2.5 PowerShellGet {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability…}
Script 2.2.6 PSReadLine {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Se…
PS /Users/sixdog/Documents/PowerShell>
- 再次执行查询
PS /Users/sixdog/Documents/PowerShell> ./test.ps1
A valid license is required to use MySQLCmdlets.
Would you like to install a license now? (You may use "TRIAL" as the Product Key to activate a trial license.)
[Y] Yes [N] No [?] Help (default is "Y"): y
cmdlet Get-License at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
Email: ssssssss@gmail.com
Name: sixdog
ProductKey: TRIAL
Downloading license ...
Verifying license data...
License installation succeeded.
- 上一步操作查了下是试用版,感觉没啥意思,不想用,再找找别的连接数据库的模块
- 远程访问需要安装「 Connector/NET x.x.xx 」,不符合不需要安装就能用原则
- 还有的需要导入[Reflection.Assembly]::LoadFile(“C:\Program Files\CData\CData ADO.NET Provider for MySQL\lib\System.Data.CData.MySQL.dll”)
- 宗于以上原因,使用mysql需要安装东西,放弃。。。