Use Get-Content
para ler o arquivo e canalize |
para o seu comando. Use &
para executar o comando.
get-content 'c:\folder\backup.sql' | &"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql.exe" -u user --password=pass dbnamedbname
Digamos que eu tenha o seguinte comando:
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql" -u user --password=pass dbname < backup.sql
Funciona bem em cmd
, mas no PowerShell eu recebo o seguinte:
At line:1 char:53
+ "C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql" -u user --password=pass dbna ...
+ ~~
Unexpected token '-u' in expression or statement.
At line:1 char:56
+ "C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql" -u user --password=pass dbna ...
+ ~~~~
Unexpected token 'user' in expression or statement.
At line:1 char:84
+ ... rd=pass dbname < backup.sql
+ ~
The '<' operator is reserved for future use.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
Se eu remover as aspas duplas, o comando me causará menos erros no PowerShell, mas não funcionará em cmd
, causando-me este erro:
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
No PowerShell, recebo isso:
At line:1 char:82
+ ... rd=pass dbname < backup.sql
+ ~
The '<' operator is reserved for future use.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RedirectionNotSupported
Então, como eu alinho o backup.sql em mysql
?
No Linux, acho que o pipping funcionaria. por exemplo.
C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql -u user --password=pass dbname | cat backup.sql
Mas isso me dá esse erro:
C:\Program : The term 'C:\Program' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql -u user --password=pass dbname ...
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Program:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Se eu adicionar novamente as aspas duplas, também não funcionará.
Alguma idéia?