使用 Force 在 Windows 上导入大型 MySQL .sql 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6365191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Import large MySQL .sql file on Windows with Force
提问by getWeberForStackExchange
I would like to import a 350MB MySQL .sql file on a Windows 7 machine. I usually do this by using
我想在 Windows 7 机器上导入 350MB MySQL .sql 文件。我通常通过使用来做到这一点
mysql -uuser -p -e "source c:/path/to/file.sql" database
since < doesn't work in Powershell.
因为 < 在 Powershell 中不起作用。
My .sql file has an error in it this time. I'd prefer to just skip the bad row and continue the import. How can I force the import to continue on Windows?
这次我的 .sql 文件有错误。我宁愿跳过坏行并继续导入。如何强制在 Windows 上继续导入?
On a unix/linux based system, I could use
在基于 unix/linux 的系统上,我可以使用
mysql --force ... < file.sql
but --force doesn't seem to work with the -e "source ..." command (understandably so).
但是 --force 似乎不适用于 -e "source ..." 命令(可以理解)。
Thanks, Mike
谢谢,迈克
回答by Joel B Fant
You're probably going to have to have Powershell execute this in the standard console in order to use <
properly. Technically you could use get-content
and pipe the output to mysql
, but I've always found that to be slow, and it somehow still keeps the file contents in memory of the Powershell session.
您可能必须让 Powershell 在标准控制台中执行此操作才能<
正确使用。从技术上讲,您可以使用get-content
并将输出通过管道传输到mysql
,但我总是发现这很慢,而且它仍然以某种方式将文件内容保留在 Powershell 会话的内存中。
This is how I would execute it from the Powershell prompt (changed file path to include spaces to demonstrate inner quotes, just in case):
这是我从 Powershell 提示符执行它的方式(更改文件路径以包含空格以演示内部引号,以防万一):
cmd /C 'mysql -uuser -p --force < "C:\path\with spaces\to\file.sql"'
[GC]::collect()
would apparently clear it up the memory, but you can't do that until after it's done anyway. When it comes to mysql
and mysqldump
, I don't bother with Powershell. The default encoding used in >
is Unicode, making dump files twice as big out of Powershell as out of cmd
unless you remember to write | out-file dump.sql -enc ascii
instead of > dump.sql
.
[GC]::collect()
显然会清除内存,但无论如何你都不能这样做。说到mysql
and mysqldump
,我不介意Powershell。编码中使用的默认>
是Unicode,使转储文件的两倍大出的PowerShell作为出的cmd
,除非你记得写| out-file dump.sql -enc ascii
替代> dump.sql
。
回答by superjos
I'd suggest to also have a look at this SO answer, that takes advantage of source
SQL command:
我建议也看看这个 SO answer,它利用了source
SQL 命令: