0

I've tried a ton of different variations of this, but I can't get it to work. I am trying to run mysqldump to export a database (in this case called global).

PS C:\Users\Administrator> &"$mysqlpath\mysqldump.exe -u$mysqluser -p$mysqlpass --databases global | Out-File $env:TEMP\database_backup\global_$timestamp.sql -Encoding UTF8"
& : The term 'C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe -ubackup -pbackup_password --databases global | Out-File C:\Users\ADMINI~1\AppData\Local\Temp\2\database_backup\global_2013-12-11T11:47:28.sql -Encoding UTF8' 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:2
+ &"$mysqlpath\mysqldump.exe -u$mysqluser -p$mysqlpass --databases global | Out-Fi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Program File... -Encoding UTF8:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

It looks like it is being exploded into the proper variable names, but I can't get it to run.

UPDATE: So that was the right answer, I had a : in the timestamp. My other problem was solved by putting the variables inside double quotes (")

1 Answer 1

2

You are telling Powershell to run an EXE named

&"$mysqlpath\mysqldump.exe -u$mysqluser -p$mysqlpass --databases global | Out-File $env:TEMP\database_backup\global_$timestamp.sql -Encoding UTF8"

So remove the quotes (") and try again. Like so,

& $mysqlpath\mysqldump.exe -u$mysqluser -p$mysqlpass --databases global | Out-File $env:TEMP\database_backup\global_$timestamp.sql -Encoding UTF8

Sign up to request clarification or add additional context in comments.

4 Comments

On top of that, colons aren't valid as parts of a file name in Windows unless they're part of the drive designation, so it's likely that your Out-File statement will fail, too.
I changed it to &$mysqlpath\mysqldump.exe -u$mysqluser -p$mysqlpass --databases global | Out-File $temppath\database_backup\global_$timestamp.sql -Encoding UTF8 But still get Out-File : The given path's format is not supported. At line:1 char:74 + &$mysqlpath\mysqldump.exe -u$mysqluser -p$mysqlpass --databases global | Out-Fil ... +CategoryInfo : OpenError: (:) [Out-File], NotSupportedException + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
Your timestamp variable $timestamp seems to be expanding to 2013-12-11T11:47:28 which won't work because you can't have a : in the file path.
Your right, I didn't even think about $timestamp. I'm still doing something wrong after I fixed timestamp. It looks like it's not using the $mysqluser variable. mysqldump: Got error: 1045: Access denied for user '$mysqluser'@'localhost' (using password: YES) when trying to connect PS C:\Users\Administrator\AppData\Local\Temp\2> $mysqluser backup

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.