Frequent MySQL Connection Error

I get this problem frequently:

Can't connect to MySQL localhost
ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2)

How do I fix it?

Start with checking your mysql/mariadb logfile.