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:
- PDOException : SQLSTATE[HY000] [2006] MySQL server has gone away
-
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!
- 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:
default-authentication-plugin=mysql_native_password
- And for the second error, go to your laravel app and open the .env file and then, change your
DB_HOST=127.0.0.1
toDB_HOST=localhost
.
You're good to go now!