Posted in
Hosting & IIS7,
Windows Powershell,
Windows Server |
No Comment | 4,022 views | 23/06/2009 02:50
You can change or set MySQL user password from Powershell with MySQL connector:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| # Powershell Args
$dbusername = $args[0] # user01073
$dbpassword = $args[1] # RadoreTelekom
$dbname = $args[2] # db01073
# Add MySQL Data Connector
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
# Open Connection to SQL Server
$connStr = "server=127.0.0.1;port=3306;uid=root;pwd=SQLPassword"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
# Set MySQL User Password
$setmysqlpassword = "SET PASSWORD FOR '" + $dbusername + "'@'localhost' = PASSWORD('" + $dbpassword + "')"
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($setmysqlpassword, $conn)
$da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$da.Fill($ds) |
# Powershell Args
$dbusername = $args[0] # user01073
$dbpassword = $args[1] # RadoreTelekom
$dbname = $args[2] # db01073
# Add MySQL Data Connector
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
# Open Connection to SQL Server
$connStr = "server=127.0.0.1;port=3306;uid=root;pwd=SQLPassword"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
# Set MySQL User Password
$setmysqlpassword = "SET PASSWORD FOR '" + $dbusername + "'@'localhost' = PASSWORD('" + $dbpassword + "')"
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($setmysqlpassword, $conn)
$da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$da.Fill($ds)
Also I used arguments so you can call this powershell script from your panel.