I'm on a Mac OS Yosemite using Laravel 5.0.
While in my local environment, I run php artisan migrate
I keep getting :
Access denied for user 'homestead'@'localhost' (using password: YES)
Configuration
Here is my .env
APP_ENV=local
APP_DEBUG=true
APP_KEY=*****
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
app\config\database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'unix_socket' => '/tmp/mysql.sock',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
]
How do I avoid this kind of error ?
I've tried :
in app/database.php
Replace localhost
with 127.0.0.1
'host'=> env('DB_HOST', 'localhost')
-->'host' => env('DB_HOST', '127.0.0.1')
Also, in .env
DB_HOST=localhost
--> DB_HOST=127.0.0.1
Try specify environment
php artisan migrate --env=local
Check to see if the MySQL is running by run
mysqladmin -u homestead -p status Enter password: secret
I got
Uptime: 21281 Threads: 3 Questions: 274 Slow queries: 0 Opens: 327 Flush tables: 1 Open tables: 80 Queries per second avg: 0.012
Which mean it's running.
Check MySQL UNIX Socket (This step work for me)
The reason of Access denied for user ‘homestead’@’localhost’ laravel 5 error is caching-issue of the .env.php file cause Laravel 5 is using environment based configuration in your .env file.
1. Go to your application root directory and open .env file (In ubuntu may be it’s hidden so press ctrl+h to show hidden files & if you are in terminal then type : ls -a
to show hidden files) in your editor and change database configuration setting. then save your .env file
DB_HOST=localhost
DB_DATABASE=laravelu
DB_USERNAME=root
DB_PASSWORD=''
2. then restart your apache server/web server. and refresh your page and you have done
3. If still issue try to run below command to clear the old configuration cache file.
php artisan config:clear
Now you are done with the error