简体   繁体   English

MySQLDUMP和CMD / Powershell之间的区别

[英]MySQLDUMP and the difference between CMD/Powershell

When i make a mysql dump with this command from a powershell, i get a unusable and a larger file. 当我从Powershell使用此命令进行mysql dump时,我得到了一个不可用的较大文件。 When i use the same command from a CMD window then i get a SQL file with the same size when i do a export with the GUI tool and i can use the GUI aswell as the commandline to restore the backup. 当我从CMD窗口中使用相同的命令时,使用GUI工具进行导出时,我会得到一个具有相同大小的SQL文件,并且可以使用GUI以及命令行来还原备份。 With the dump made with a powershell, it refuses to restore the backup. 使用Powershell创建转储后,它拒绝还原备份。

i use this command E:\\Script\\mysqldump.exe -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\\\location\\backup.sql 我使用以下命令E:\\ Script \\ mysqldump.exe -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases> \\\\ location \\ backup.sql

This is the powershell script i am intended to use: 这是我打算使用的powershell脚本:

$Date = [Int] (Get-Date).DayOfWeek
$Su = 0
$Mo = 1
$Tu = 2
$We = 3
$Th = 4
$Fr = 5
$Sa = 6

If ($Date -eq $Mo) 
{
 & "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\mobackup.sql
}

ElseIf ($Date -eq $Tu) 
{
 & "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\tubackup.sql
}

ElseIf ($Date -eq $We)
{
 & "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\webackup.sql
}

ElseIf ($Date -eq $Th)
{
 & "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\thbackup.sql
}

ElseIf ($Date -eq $Fr)
{
 & "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\frbackup.sql
}

ElseIf ($Date -eq $Sa)
{
 & "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\sabackup.sql
}

ElseIf ($Date -eq $Su)
{
 & "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases > \\location\subackup.sql
}

First of all, you can rewrite your script in a much simpler way: 首先,您可以用一种更简单的方式重写脚本:

$dayOfWeek = (Get-Date).DayOfWeek.ToString().ToLower().substring(0, 2)
$backupFile = $dayOfWeek + "backup.sql"

& "E:\Script\mysqldump.exe" -u root -ppassword -h 127.0.0.1 xticket --lock-tables --disable-keys --add-drop-table --routines --databases | Out-File $backupFile -Encoding ASCII

Note that I used Out-File instead of piping to a file. 请注意,我使用Out-File而不是管道传输到文件。 I suspect the difference in behaviour you see is due to file encoding (ASCII/UTF8). 我怀疑您看到的行为差异是由于文件编码(ASCII / UTF8)引起的。 Not sure this is your problem, however. 但是,不确定这是您的问题。 I don't have mysqldump installed on my machine and I cannot test it. 我的机器上没有安装mysqldump,我无法对其进行测试。 Just pure guess. 纯粹是猜测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PowerShell 的 echo 和 CMD 的 echo 的区别 - Difference between PowerShell's echo and CMD's echo 比较 2 个文本文件并显示它们之间的差异(PowerShell 或 CMD) - Compare 2 text files and display the difference between them (PowerShell or CMD) PowerShell和cmd.exe命令语法有什么区别? - What is the difference between PowerShell and cmd.exe command syntax? 在Windows中删除文件时,CMD和PowerShell有什么区别? - What's the difference between CMD and PowerShell when deleting a file in Windows? 如何使用 Powershell 或 cmd 计算文件中开始时间和结束时间之间的分钟差 - How to calculate difference in minutes between START and END times in a file using Powershell or cmd $?之间的区别?和PowerShell中的$ LastExitCode - Difference between $? and $LastExitCode in PowerShell - 命令和ScriptBlock Powershell之间的区别 - Difference between - command and ScriptBlock Powershell Powershell-“-”(破折号)和“。”(连字符)之间的区别 - Powershell - difference between “-” (dash) and “.” (hyphen) PowerShell:数组表示法之间的区别? - PowerShell: Difference between array notation? PowerShell控制台和PowerShell ISE之间的区别 - Difference between PowerShell Console and PowerShell ISE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM