Laravel 6 - php 7.4 | MySQL Errors Fix SQLSTATE[HY000] [2006] & SQLSTATE[HY000] [2002]

So, when I was creating my first laravel 6 app and trying to connect it to the database, I got these two errors:

  1. PDOException : SQLSTATE[HY000] [2006] MySQL server has gone away
  2. Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = chat_db and table_name = migrations and table_type = 'BASE TABLE')

As I Googled around for a bit, I found 2 very simple solutions!

  1. For the first problem, you have to edit your MySQL configuration file which should be in /usr/local/etc/my.cnf in your Mac.
    Open the file and add the following line to it:
  1. And for the second error, go to your laravel app and open the .env file and then, change your DB_HOST= to DB_HOST=localhost.

You're good to go now!