title: How to import .sql file into MySQL using PowerShell script?
body: <p>I'm trying to import a dump file (.sql file containing CREATE/DROP/INSERT commands) into a remote MySQL server from a windows environment. I've got this PowerShell script to do the job for me by using <em>"MySQL shell utility"</em> functionalities installed in my environment</p>
  
  <pre class="lang-bsh prettyprint-override"><code>Set-ExecutionPolicy RemoteSigned
  Add-Type –Path 'C:\Program Files (x86)\MySQL\MySQL Connector Net 8.0.11\Assemblies\v4.5.2\MySql.Data.dll'
  $Connection = [MySql.Data.MySqlClient.MySqlConnection]@{ConnectionString='server=192.168.100.100;Encrypt=false;uid=myUser;pwd=myPass;database=myDB;'}
  $Connection.Open()
  $sql = New-Object MySql.Data.MySqlClient.MySqlCommand
  $sql.Connection = $Connection
  $sql.CommandText = "SOURCE D:/MySQL_Dumps/myFile.sql"
  $sql.ExecuteNonQuery()
  $Reader.Close()
  $Connection.Close()
  </code></pre>
  
  <p>I can connect to the server and execute basic <code>SELECT</code> queries, using <code>ExecuteNonQuery()</code>/<code>ExecuteScalar()</code>/<code>ExecuteReader()</code> methods, but receiving an error for this specific SOURCE command:</p>
  
  <pre>
  Exception calling "ExecuteNonQuery" with "0" argument(s): "You have an error
  in your SQL syntax; check the manual  that corresponds to your MySQL server
  version for the right syntax to use near 'SOURCE
  D:/MySQL_Dumps/myFile.sql' at  line 1" At line:8 char:1
  + $sql.ExecuteNonQuery()
  + ~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : MySqlException
  </pre>
  
  <p>I tried several alternatives to enter the path, like using double slashes or double backslashes but encountered the same error. Can anyone help on this?</p>