Example
1# Import values with details connexion
2. .\values.ps1
3
4$scriptFilePath ="$MyPath\Install\MysqlBase\Script.sql"
5
6# Load the required DLL file (depend on your connector)
7[void][System.Reflection.Assembly]::LoadFrom("C:\Program Files (x86)\MySQL\MySQL Connector Net 8.0.23\Assemblies\v4.5.2\MySql.Data.dll")
8
9# Load in var the SQL script file
10$scriptContent = Get-Content -Path $scriptFilePath -Raw
11
12# Execute the modified SQL script
13$Connection = [MySql.Data.MySqlClient.MySqlConnection]@{
14 ConnectionString = "server=$MysqlIP;uid=$MysqlUser;Port=3306;user id=$MysqlUser;pwd=$MysqlPassword;database=$MysqlDatabase;pooling=false;CharSet=utf8;SslMode=none"
15 }
16 $sql = New-Object MySql.Data.MySqlClient.MySqlCommand
17 $sql.Connection = $Connection
18 $sql.CommandText = $scriptContent
19 write-host $sql.CommandText
20 $Connection.Open()
21 $sql.ExecuteNonQuery()
22 $Connection.Close()
Comments