The operation of database tables is also an important part of it automation management.
How do we manage MySQL data sheets?
Here's an example:
Objective to obtain a row field of a table from a list
1
Then you need to install Mysql. NET Connector
http://www.cr173.com/soft/50789.html Download Link
2 Code Content
############################################ #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;p wd= $Password;d atabase=$ database;charset= $charset "$connection = new-object mysql.data.mysqlclient.mysqlconnection ($ connectionString) $connection. Open () #GET memeberid$getsql= for an account "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 ' total ' $recordCount ' record ' $memberid = $getid. tables.rows.member_id# Update this ID into the ad binding table in $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 ()
This article is from the "operation and maintenance of life" blog, please make sure to keep this source http://lixiaosong.blog.51cto.com/705126/1689884
How to manage MySQL through PowerShell