简体   繁体   English

使用Force在Windows上导入大型MySQL .sql文件

[英]Import large MySQL .sql file on Windows with Force

I would like to import a 350MB MySQL .sql file on a Windows 7 machine. 我想在Windows 7机器上导入一个350MB的MySQL .sql文件。 I usually do this by using 我通常通过使用来做到这一点

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. 这次我的.sql文件有错误。 I'd prefer to just skip the bad row and continue the import. 我宁愿跳过坏行并继续导入。 How can I force the import to continue on Windows? 如何强制导入在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 谢谢,迈克

You're probably going to have to have Powershell execute this in the standard console in order to use < properly. 您可能必须让Powershell在标准控制台中执行此操作才能正确使用< 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. 从技术上讲,你可以使用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. [GC]::collect()显然会清除内存,但是在完成之后你就不能这样做了。 When it comes to mysql and mysqldump , I don't bother with Powershell. 说到mysqlmysqldump ,我不打扰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 >使用的默认编码是Unicode,使得转储文件的容量是Powershell的两倍,而不是cmd除非你记得写| out-file dump.sql -enc ascii | out-file dump.sql -enc ascii instead of > dump.sql . | out-file dump.sql -enc ascii而不是> dump.sql

我建议也看看这个SO答案 ,它利用了source SQL命令:

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM