Mac mini turns off automatically by itself Ive got a mid 2012 mac mini which i have used constantly without issue for about 5 years. Today it seems to have developed a weird fault were it powers off by itself. I powered it back on just after lunch as it was off and when i came back it had turned itself off again. 

At first i thought it might be a loose connection with the power cable or extension cord, but i checked them all and they are in tightly with plenty of slack on the cable. 

As per suggestion in comments ive opened up the shutdown cause log and it seems to be caused by 

localhost kernel[0]: Preview shutdown cause: -62 There are a couple of 5 listings also.
It sounds like you might have an issue with the OS or an application that's crashing the OS.


A shutdown cause of 5 is a normal shutdown and nothing to worry about.  It's saying that it "shutdown correctly."
Shutdown of -62 is generally due to an unresponsive application.  


You should start with booting into Safe Mode to see if it's something being loaded.

Other options would be to wipe the drive with a clean OS (also a good time to upgrade the drive if you're still using an old spinning one). 

Personally, I would start with booting from an external drive, a clean copy of macOS to see if the problem goes away before embarking on swapping out hardware.