标签:下载链接
对数据库表的操作也是IT自动化管理的一项重要内容。
我们如何对MYSQL数据表进行管理呢?
下面举一个例子:
目的实现从一个表里获取一个表的某行字段
1
然后需要安装 Mysql .net Connector
http://www.cr173.com/soft/50789.html 下载链接
2 代码内容
############################################ #Author:Lixiaosong #lixiaosong8706@gmail.com #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
标签:下载链接
原文地址:http://lixiaosong.blog.51cto.com/705126/1689884