Run a SQL Script Against MySQL using Powershell


I have a Powershell script that backs up my MySQL DB’s each night using mysqldump. This all works fine but I would like to extend the script to update a reporting db (db1) from the backup of the prod db (db2). I have written the following test script but it does not work. I have a feeling the problem is the reading of the sql file to the CommandText but I am not sure how to debug.

Any assistance would be appreciated. Thanks.


This line:

Returns an array of strings. When that gets assigned to something expecting a string then PowerShell will concatenate the array of strings into a single string using the contents of the $OFS (output field separator) variable. If this variable isn’t set, the default separator is a single space. Try this instead and see if it works:

Or if you’re on PowerShell 2.0:


Run a SQL Script Against MySQL using Powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply