使用Force在Windows上导入大型MySQL .sql文件 [英] Import large MySQL .sql file on Windows with Force
问题描述
我想在Windows 7计算机上导入一个350MB的MySQL .sql文件。我通常使用
I would like to import a 350MB MySQL .sql file on a Windows 7 machine. I usually do this by using
mysql -uuser -p -e "source c:/path/to/file.sql" database
因为<在Powershell中不起作用。
since < doesn't work in Powershell.
这次我的.sql文件中有错误。我宁愿跳过坏行并继续导入。如何强制导入在Windows上继续?
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?
在基于unix / linux的系统上,我可以使用
On a unix/linux based system, I could use
mysql --force ... < file.sql
但是--force似乎不适用于-e源代码.. 。命令(可以理解的是这样)。
but --force doesn't seem to work with the -e "source ..." command (understandably so).
谢谢,
迈克
推荐答案
您可能必须让Powershell在标准控制台中执行此操作才能正确使用<
。从技术上讲,你可以使用 get-content
并将输出传递给 mysql
,但我总是发现它很慢,它以某种方式仍将文件内容保存在Powershell会话的内存中。
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提示符执行它的方法(更改文件路径以包含空格到演示内部引用,以防万一):
This is how I would execute it from the Powershell prompt (changed file path to include spaces to demonstrate inner quotes, just in case):
cmd /C 'mysql -uuser -p --force < "C:\path\with spaces\to\file.sql"'
[GC] :: collect()
显然会清除内存,但是在完成之后你才能这样做。说到 mysql
和 mysqldump
,我不打扰Powershell。 >
中使用的默认编码是Unicode,使得转储文件的容量是Powershell的两倍,而 cmd
除非你记得写 | out-file dump.sql -enc ascii
而不是> dump.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
.
这篇关于使用Force在Windows上导入大型MySQL .sql文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!