5

I use the command php artisan migrate to migrate my db in laravel 5 .. it gives me an error:

exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)'

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
shimaa
  • 79
  • 1
  • 1
  • 2
  • Have you checked the correct password is being used? – CᴴᵁᴮᴮʸNᴵᴺᴶᴬ Feb 21 '15 at 09:56
  • possible duplicate of [problems with database connection in laravel 5](http://stackoverflow.com/questions/28389697/problems-with-database-connection-in-laravel-5) – baao Feb 21 '15 at 10:06
  • Please see my answer in the question I posted above, you need to change the values for your connection in the .env file – baao Feb 21 '15 at 10:07
  • You may Follow the below link :[http://stackoverflow.com/questions/29756194/access-denied-for-user-homesteadlocalhost-using-password-yes](http://stackoverflow.com/questions/29756194/access-denied-for-user-homesteadlocalhost-using-password-yes/30340330#30340330) – abSiddique Jan 20 '16 at 06:18

11 Answers11

9

Sometime in the future. Try to clear your config first

php artisan config:clear. 

Close all the terminal /cmd windows and then restart terminal/CMD and this should get rid of the error message. See if it works.

Krishneil
  • 1,432
  • 1
  • 18
  • 26
4

In your Laravel .env file, alter the variables accordingly to match your desired settings.

If you're using something like XAMMP or EasyPHP with a mysql db, perhaps use the following setup

 DB_HOST=localhost
 DB_DATABASE=mysql
 DB_USERNAME=root
 DB_PASSWORD=''
jurg Hurg
  • 41
  • 2
3

If you have all your configurations ok in the .env file then you should:

In Terminal run this command that lists processes with php in it:

ps -ef | grep php

then:

501 4529 599 0 Sat03PM ttys000 0:00.15 php artisan serve

501 4533 4529 0 Sat03PM ttys000 0:25.11 /usr/bin/php -S 127.0.0.1:8000 /Applications/XAMPP/xamppfiles/htdocs/ds7/laravel/coffeeshop/server.php

Use the kill command to terminate the process (Notice: The process id is the second column group of numbers.)

kill 4529
kill 4533

Then run php artisan config:clear

Finally, restart server with:

php artisan serve
rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38
Domingo
  • 165
  • 1
  • 4
3

Run the following command:

php artisan cache:clear
php artisan config:cache
Ajmal Aamir
  • 1,085
  • 8
  • 8
1
  'mysql' => [
                'driver' => 'mysql',
                'host' => env('DB_HOST', '127.0.0.1'),
                'port' => env('DB_PORT', '3306'),
                'database' => 'laravel',
                'username' => 'root',
                'password' => 'PASSWORD IF HAVE OTHERWISE LEAVE IT BLANK ',
                'unix_socket' => env('DB_SOCKET', ''),
                'charset' => 'utf8mb4',
                'collation' => 'utf8mb4_unicode_ci',
                'prefix' => '',
                'strict' => true,
                'engine' => null,
            ],

REMOVE THE ENV values from db,host and password and put them direct

anil sidhu
  • 963
  • 1
  • 9
  • 24
0

This question was asked several times before .. checkout the best answers I found :

The problems behind this error could be :

  • Your .env file and config/database.php are incorrect.
  • You didn't set the correct unix_socket value in your config file, checkout Question 2.
  • You are trying to run the php artisan migrate:install from your local machine. You should SSH into the VM homestead ssh and run your migrations from there, checkout Question 1.
Community
  • 1
  • 1
Mohamed Salem Lamiri
  • 5,767
  • 6
  • 34
  • 47
0

in your database.php file, take off 'DB_DATABASE' 'DB_USERNAME' 'DB_PASSWORD'

and replace with your database name, username and password

this will work fine for u.

0

Edit .env file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=yourdbname
DB_USERNAME=yourusername
DB_PASSWORD=yourpassword

and type in your cmd

php artisan migrate

it will work for sure

Y. Joy Ch. Singha
  • 3,056
  • 24
  • 26
0

In your .env file change DB_PORT from

DB_PORT=3306

to

DB_PORT=33060

refrence to https://laravel.com/docs/5.4/homestead#connecting-to-databases

becarefull about last zero

0

Two way to solve it

Open your database config file (laravel_root/config/database.php) & search for the below code block.

'host' => env('DB_HOST', 'localhost'),
'database'  => env('DB_DATABASE', 'blog'),
'username'  => env('DB_USERNAME', 'root'),
'password'  => env('DB_PASSWORD', ''),

Change the code block as below

'host'      => 'enteryourHostName',
'database'  => 'ebterYourDatabastName',
'username'  => 'enterYoutDatabaseUsername',
'password'  => 'enterYourDatabasePassword',

Second way (Recommended by Laravel)

Check your Laravel root there have a file call .env if not exist, look for .env.example, copy/rename it as .env after that the file looks blow !

APP_ENV=local
APP_DEBUG=true
APP_KEY=someRandomNumber

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null

Modify the below block as follow

DB_HOST=yourHostName
DB_DATABASE=yourDatabaseName
DB_USERNAME=yourDatabaseUsername
DB_PASSWORD=youPassword

This Works for me.

Aryan Sharma
  • 119
  • 1
  • 1
  • 11
-1

Once you changed your .env file then you must restart the server.

In laravel in command prompt, type:

php artisan serve
Sanju Kaniyamattam
  • 501
  • 1
  • 4
  • 14