Laravel from Scratch - Traversy YouTube - SQLSTATE[HY000] [1045] error when run PHP artisan migrate I'm running PHP 7.4.9, Laravel 8 and MAMP 6.0.1 and am learning Laravel.
Those of you running MAMP and following this excellent tutorial will find in Video 5 that you will get this error when attempt to run the PHP artisan migrate command in video #5:
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = lsapp and table_name = migrations and table_type = 'BASE TABLE')
It looks like a basic mySQL issue but it's not, it's due to some missing configuration in the defaul Laravel configuration for MAMP users. I spent ages attempting to resolve and found bits of helpful and conflicting info across different threads so thought it would be useful to combine the solution in one place...
The solution...
For MAMP users, there's a line missing from the default .env file in Laravel which basically instructs Laravel where to find mySQL:
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

You also need to change the DB_HOST and DB_PORT settings for MAMP.
This works for a default MAMP installation:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=8889
DB_DATABASE=lsapp
DB_USERNAME=root
DB_PASSWORD=root
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

If you have set a username / password you should use them of course ...