Windows – choose which CPUs / Cores to be used by MySQL

MySQLmysql5windowswindows-server-2008windows-server-2008-r2

I have a Windows VPS (Windows 2008 R2 x64) that runs a couple WordPress blogs and other few ASP.NET things. The VPS runs 2 CPUs (for example).

With ASP.NET, in such situation, I usually set the app pool to use one CPU / Core, and SQL Server to use the other one (just change it in the server properties).

In MySQL, can I tell it which CPU(s) / Core(s) to use?

Best Answer

Because this actually bugged me I did some extra digging. You can actually set affinity using powershell (!) that should be available for the web edition

create a simple script affinity.ps1

$proc = GET-PROCESS mysqld
$proc.ProcessorAffinity = 0x9

The number (0x9) is in hex and it depends on your cores. Each core has a corresponding decimal value of 2^(n-1) where n is the core number.

So if you want to assign mysql to cores 1 & 4 you add the values of the corresponding cores (1+8) and covert into hex. If you wanted cores 7 & 8 the value would be (64+128) ie 0xC0 or whatever the permutations in between.

Then just schedule the above script to execute on start-up.