I know this is an old thread, but there is an easier way.
Change the default:
define('DB_HOST', 'localhost');
To:
define('DB_HOST', 'localhost:/tmp/mysql.sock');
If you socket is in a non-standard location, change the “/tmp/mysql.sock” to your socket path, just don’t forget the colon between “localhost” and the path.