mysql - Cannot run a database restore on Powershell because of < character -


i'm trying run following command:

&$parameterhash["mysql"] -u $parameterhash["user"] -p"$($parameterhash['password'])" -h $parameterhash["host"] $parameterhash['database'] `< $parameterhash['backup-path'] 

pay attention part of whole command:

$parameterhash['database'] `< $parameterhash['backup-path'] 

this syntax of mysql command-line restore backup (i.e. a sql script) file system location given database name.

first of all, had escape > in powershell backtick.

the issue entire command isn't recognized mysql command line when run powershell. once run it, mysql outputs help.

if output command string , try run in regular cmd (i.e. cmd.exe) works expected.

for now, can't figure out what's going on.

update

i've tried this:

$restoreargs = "-u $($parameterhash["user"]) -p""$($parameterhash['password'])"" -h $($parameterhash["host"]) $($parameterhash['database']) < $($parameterhash['backup-path'])" start-process $parameterhash["mysql"] $restoreargs 

...and got same result.

powershell doesn't support input redirection, output redirection. don't have mysql @ hand right now, can't test, try

get-content $parameterhash['backup-path'] | &$parameterhash["mysql"] -u $parameterhash["user"] -p"$($parameterhash['password'])" -h $parameterhash["host"] $parameterhash['database'] 

if input must single string call get-content parameter -raw (powershell v3 , newer):

get-content $parameterhash['backup-path'] -raw | ... 

or pipe get-content output through out-string first:

get-content $parameterhash['backup-path'] | out-string | ... 

another option run commandline cmd, support input redirection:

$mysql  = $parameterhash["mysql"] $user   = $parameterhash["user"] $pass   = $parameterhash['password'] $server = $parameterhash["host"] $db     = $parameterhash['database'] $backup = $parameterhash['backup-path']  cmd /c "$mysql -u $username -p $password -h $server -d $db < $backup" 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -