Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell pipe file contents into application without loading file in memory

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?

like image 751
cbednarski Avatar asked Jan 25 '11 00:01

cbednarski


1 Answers

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.

like image 127
Tony Avatar answered Nov 01 '22 03:11

Tony