1

I am trying to figure out how to run this loop asynchronously.

Get-ChildItem -Filter *.sql | Foreach-Object {

    $database = $_.Name

    mysql -u root -e "
        DROP DATABASE IF EXISTS $database;
        CREATE DATABASE $database;
        USE $database;
        SOURCE $database;
    "
}

I removed a bunch of unrelated stuff form the code but that's the gist of it.

As I see it from the task manager, this program only uses one of the 12 threads my Ryzen 5 1600 has. I would like to speed things up by running them in parallel.

Achshar
  • 5,153
  • 8
  • 40
  • 70
  • How many databases are you doing this with where doing it parallel will make a significant difference in the time required? – alroc Mar 18 '18 at 10:50
  • Sounds like a duplicate of this one: https://stackoverflow.com/questions/4016451/can-powershell-run-commands-in-parallel?rq=1 – TToni Mar 18 '18 at 16:37
  • Possible duplicate of [Can Powershell Run Commands in Parallel?](https://stackoverflow.com/questions/4016451/can-powershell-run-commands-in-parallel) – TToni Mar 18 '18 at 16:38

0 Answers0