簡體   English   中英

使用PowerShell進行MySQL轉儲

[英]MySQL Dump with PowerShell

$mysqlpath = "C:\Program Files\MySQL\MySQL Server 5.6\bin"
$backuppath = "C:\Users\Tiffany\Downloads"
$username = "user"
$password = "123123"
$database = "db"
$errorLog = "error_dump.log"

$date = Get-Date
$timestamp = "" + $date.day + $date.month + $date.year + "_" + $date.hour + $date.minute

$backupfile = $backuppath + $database + "_" + $timestamp +".sql"

CD $mysqlpath
.\mysqldump.exe --user=$username --password=$password --log-error=$errorLog --result-file=$backupfile --databases $database

CD $backuppath
$oldbackups = gci *.sql*

for($i=0; $i -lt $oldbackups.count; $i++){
    if ($oldbackups[$i].CreationTime -lt $date.AddMonths(-1)){
        $oldbackups[$i] | Remove-Item -Confirm:$false
    }
}

但是,我一直得到以下內容:

mysqldump.exe : Warning: Using a password on the command line interface can be insecure.
At C:\Users\Tiffany\Desktop\mysqldump.ps1:14 char:16
+ .\mysqldump.exe <<<<  --user=$username --password=$password --log-error=$errorLog --result-file=$backupfile --databases $database
    + CategoryInfo          : NotSpecified: (Warning: Using ...an be insecure.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

我是否需要設置標志以允許此命令行?

我會回避這個問題並使用my.cnf存儲憑據而不是在powershell腳本中存儲這些數據,請參閱如何在沒有密碼提示的情況下執行mysqldump?

[mysqldump]
user=mysqluser
password=secret

http://dev.mysql.com/doc/refman/5.5/en/option-files.html http://dev.mysql.com/doc/refman/5.5/en/password-security-user.html

通過命令行選項移交憑據將使它們顯示在進程列表中(取決於誰查看進程列表,但仍然)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM