I’m trying to run a script to output some records from MySQL, however when I try and run the script it’s displaying the MySQL help file, I think the parameters are not being passed to the program correctly.
Here is the script
$path_to_MySQL = "C:\xampp\mysql\bin\mysql.exe"
$param1 = "-h XXX"
$param2 = "-D XXX"
$param3 = "-u XXX"
$param4 = "-pXXX"
$param5 = "-e ""SELECT 'Test';"""
$params = @($param1, $param2, $param3, $param4, $param5)
write-host $path_to_MySQL $params
&$path_to_MySQL $params
Now this outputs to the display,
C:\xampp\mysql\bin\mysql.exe -h XXX -D XXX -u XXX -pXXX -e "SELECT 'Test';"
ERROR 2005 (HY000): Unknown MySQL server host ' XXX'
The first line is because of the write-host line.
However, when I copy the output from here and run it straight in the console, it runs correctly. (i.e. I have the correct host details)
How can I run this line using the PowerShell Script?
What are you using as server name? Pay attention to the error message:
Unknown MySQL server host ' XXX', which quotes the host name as' XXX'(note the space) instead of'XXX'.One gotcha in Powershell is that double quote
"strings are evaluated whereas single quote'strings are not. So if your host name contains special characters, Powershell might mess ’em up. That is,Try a workaround like so,
And