如何 通過 powershell 管理 MySQL

來源:互聯網
上載者:User

標籤:下載連結

對資料庫表的操作也是IT自動化管理的一項重要內容。

我們如何對MYSQL資料表進行管理呢?

下面舉一個例子:

目的實現從一個表裡擷取一個表的某列欄位

1

然後需要安裝 Mysql .net Connector

http://www.cr173.com/soft/50789.html 下載連結

 

2 代碼內容

#############################################Author:Lixiaosong#[email protected]#For:Get And Insert Mysql Tables#Version:1.0##############################################[void][system.Reflection.Assembly]::LoadFrom("C:\\Program Files (x86)\\MySQL\\MySQL Connector Net 6.9.5\\Assemblies\\v4.5\\MySql.Data.dll")$Server="192.168.1.1"$Database="XXX" #資料庫名$user="user" #賬戶$Password="password" #密碼$connectionString = "server=$Server;uid=$user;pwd=$Password;database=$Database;charset=$charset"$connection = New-Object MySql.Data.MySqlClient.MySqlConnection($connectionString)$connection.Open()#GET 某個賬戶的MemeberID$getsql= "SELECT MEMBER_ID from  org_principal WHERE LOGIN_NAME = ‘$username‘"$getcommand = New-Object MySql.Data.MySqlClient.MySqlCommand($getsql, $connection)$dataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($getcommand)$getid = New-Object System.Data.DataSet$recordCount = $dataAdapter.Fill($getid)Write-Host ‘共有‘ $recordCount ‘條記錄‘$memberid=$getid.Tables.ROWS.MEMBER_ID#更新這個ID到AD綁定表中$insertsql = "INSERT INTO ctp_org_user_mapper (ID,TYPE,LOGIN_NAME,EX_LOGIN_NAME,EX_PASSWORD,EX_ID,MEMBER_ID,EX_UNIT_CODE) VALUES (‘$userid‘,‘ad.member‘,‘$username‘,‘$username‘,‘null‘,‘670869647114347‘,‘$memberid‘,‘$usercnname‘);"$insertcommand = New-Object MySql.Data.MySqlClient.MySqlCommand$insertcommand.Connection=$connection$insertcommand.CommandText=$insertsql$insertcommand.ExecuteNonQuery()$connection.Close()



本文出自 “營運人生” 部落格,請務必保留此出處http://lixiaosong.blog.51cto.com/705126/1689884

如何 通過 powershell 管理 MySQL

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.