使用cmd我会运行mysql -uroot database < filename.sql来导入数据库转储(从文件读取并传递给MySQL)。 但是,在powershell中<是“保留”。
相反,在PowerShell中,我使用get-content filename.sql | mysql -uroot database get-content filename.sql | mysql -uroot database 。 需要注意的是,在将filename.sql传递给MySQL之前,powershell会将filename.sql 完全读入内存 ,而在大型数据库转储时,它只会耗尽内存。
很显然,我可以通过cmd来执行此操作,但我有一些PowerShell脚本可以自动执行这样的各种任务,而且我不想将它们全部批量重写。 在这种特殊情况下, filename.sql是自动启动时通过PS参数指定的变量。
那么如何解决这个内存限制? 是否有另一种方式直接将文件内容传送到MySQL?
With cmd I'd run mysql -uroot database < filename.sql to import a database dump (read from file and pass to MySQL). However, < is "reserved" in powershell.
Instead, in powershell I use get-content filename.sql | mysql -uroot database. The caveat is that powershell reads filename.sql completely into memory before passing it along to MySQL, and with large database dumps it simply runs out of memory.
Obviously, I could execute this via cmd but I have a handful of powershell scripts automating various tasks like this and I don't want to have to rewrite them all in batch. In this particular case, filename.sql is a variable that's specified via PS parameters when the automation kicks off.
So how do I get around this memory limitation? Is there another way to pipe the file contents into MySQL directly?
最满意答案
你可以试试
mysql -uroot -pYourPassword -e "source C:\temp\filename.SQL"要么
mysql --user=root --password=YourPassword --execute="source C:\temp\filename.SQL"如果事情开始变得复杂,也许你应该编写一个执行复杂任务的C#控制台应用程序。
You can Try
mysql -uroot -pYourPassword -e "source C:\temp\filename.SQL"or
mysql --user=root --password=YourPassword --execute="source C:\temp\filename.SQL"If things start to get complicated maybe you should write a C# Console application that does the complex tasks.
更多推荐
发布评论