Laravel - Task Scheduling - SQLSTATE[HY000] [2002] No such file or directory

When creating a database connection in 'app/Console/Kernel.php' and running 'php artisan schedule:run' from CLI the following error occurred:

This can be solved by adding the location to the MySQL socket in the database configuration file 'config/database.php':

'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock'

It is also possible that the connection has failed at host, try localhost instead:

'host' => 'localhost'