Import large MySQL .sql file on Windows with Force

后端 未结 2 1608
野的像风
野的像风 2020-12-17 02:40

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         


        
相关标签:
2条回答
  • 2020-12-17 03:27

    I'd suggest to also have a look at this SO answer, that takes advantage of source SQL command:

    0 讨论(0)
  • 2020-12-17 03:29

    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.

    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() 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.

    0 讨论(0)
提交回复
热议问题