Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

fanco's avatar
Level 1

brew mysql installed and running, but php artisan migrate can't connect

Hi I installed mysql using brew as described in laracast, created a new database called mario and I can connet to mysql using terminal mysql -u root command. When I try to run php artisan migrate on a fresh copy of laravel (all needed credentials in .env set) terminal gives me this error:

Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = mario and table_name = migrations and table_type = 'BASE TABLE')

can somebody help please? Thank you in advance

0 likes
10 replies
Sinnbeck's avatar

What have you set DB_HOST to? Try either 127.0.0.1 or localhost. (my guess is that it should be 127.0.0.1)

fanco's avatar
Level 1

Thank you for the quick reply I tried both but unfortunately it didn't help.

fanco's avatar
Level 1

I tried all of above. here is part of the .env

APP_URL=http://mario.test

LOG_CHANNEL=stack

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=mario DB_USERNAME=root DB_PASSWORD=

with this setting php artisan migrate answers with:

PDOException : SQLSTATE[HY000] [2006] MySQL server has gone away

at /Users/mf/code/mario/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 66| if (class_exists(PDOConnection::class) && ! $this->isPersistentConnection($options)) { 67| return new PDOConnection($dsn, $username, $password, $options); 68| } 69|

70| return new PDO($dsn, $username, $password, $options); 71| } 72| 73| /** 74| * Determine if the connection is persistent.

fanco's avatar
Level 1

when I changed back to localhost like this: APP_URL=http://mario.test

LOG_CHANNEL=stack

DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=mario DB_USERNAME=root DB_PASSWORD=

it gives me the original error:

Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = mario and table_name = migrations and table_type = 'BASE TABLE')

NOW: I let the terminal to show me the databases and there is a database information_schema:

mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mario | | mysql | | performance_schema | | sys | +--------------------+

but when I try to connect to this database using Coda 2, there are only databases mario and sys. Could it be damaged or something? How to repair?

thank you in advance Mario

Sinnbeck's avatar

This error means that it cannot find the sql server at all

No such file or directory

That means you should use 127.0.0.1. Try setting it to that and restart mysql (or your machine)

fanco's avatar
Level 1

@sinnbeck

ok, I went back to 127.0.0.1

APP_URL=http://mario.test

LOG_CHANNEL=stack

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=mario DB_USERNAME=root DB_PASSWORD=

I restarted the machine and services too, but with this setting after php artisan migrate command it only get frozen for about 30 sec and then says this:

PDOException : SQLSTATE[HY000] [2006] MySQL server has gone away

at /Users/mariofancovic/code/mario/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 66| if (class_exists(PDOConnection::class) && ! $this->isPersistentConnection($options)) { 67| return new PDOConnection($dsn, $username, $password, $options); 68| } 69|

70| return new PDO($dsn, $username, $password, $options); 71| } 72| 73| /** 74| * Determine if the connection is persistent.

but mysqld is running all the time. Please read also my comment before about the information_schema I am not able to connect with even if terminal says it is there.

fanco's avatar
Level 1

SOLVED @sinnbeck

Finally after hours of research I found the problem. It does not work with the current version of MYSQL 8. I had to downgrade mysql to version 5,7,28 following this article:

https://medium.com/@at0dd/install-mysql-5-7-on-mac-os-mojave-cd07ec936034

with 5.7.28 works all as in the laracast for Laravel 6. Maybe it would be nice to mention this caveat in the tutorial. thank You once more sinnbeck for triyng to help.

Mario

1 like
vuongphan's avatar

I had the same error, but I found a solution.

For Laravel 6 and MySQL 8.0.18, PHP 7.4, the IDENTIFIED of the MySQL user must be caching_sha2_password

For example: ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'secret';

1 like
joemags's avatar

[Ubuntu 19.10, Laravel 6.x and MySQL 8; Solved] Best solution

$ mysql -u root -p
mysql> CREATE USER 'joemags'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'secret';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'joemags'@'localhost' WITH GRANT OPTION;
2 likes

Please or to participate in this conversation.