Laravel-4-Generators icon indicating copy to clipboard operation
Laravel-4-Generators copied to clipboard

Access denied for user 'homestead'@'localhost'

Open yaya-git opened this issue 10 years ago • 38 comments

I try to run: php artisan migrate:install

But I got the following error: [PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)

yaya-git avatar Jul 03 '14 18:07 yaya-git

Check your database login credentials On 3 Jul 2014 12:49, "yaya-git" [email protected] wrote:

I try to run: php artisan migrate:install

But I got the following error: Access denied for user 'homestead'@'localhost' (using password: YES)

— Reply to this email directly or view it on GitHub https://github.com/JeffreyWay/Laravel-4-Generators/issues/348.

SilverPaladin avatar Jul 03 '14 19:07 SilverPaladin

My credentials are correct, I assign the file config.inc.php $cfg['Servers'][$i]['AllowNoPassword'] = TRUE; My configuration is correct?

    'mysql' => array(
        'driver'    => 'mysql',
        'host'      => '127.0.0.1',
        'database'  => 'blog',
        'username'  => 'root',
        'password'  => '',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',

    ),

yaya-git avatar Jul 03 '14 21:07 yaya-git

What are the credentials you have set for mysql, and can you connect with those credentials with mysql client? The error you published is coming from mysql. Also what is the default driver you chose in larvae Conlig? On 3 Jul 2014 15:05, "yaya-git" [email protected] wrote:

My credentials are correct, I assign the file config.inc.php $cfg['Servers'][$i]['AllowNoPassword'] = TRUE; My configuration is correct?

'mysql' => array(
    'driver'    => 'mysql',
    'host'      => '127.0.0.1',
    'database'  => 'blog',
    'username'  => 'root',
    'password'  => '',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',

),

— Reply to this email directly or view it on GitHub https://github.com/JeffreyWay/Laravel-4-Generators/issues/348#issuecomment-47984762 .

SilverPaladin avatar Jul 04 '14 00:07 SilverPaladin

It is clear that you've set your environment to local, so you also need to set your database configuration on your local environment. So go to the app folder > config folder there's a local folder inside of which there's a database.php file. Set your database configurations there and the sky will stop falling on you!

DerrickJames avatar Jul 09 '14 06:07 DerrickJames

@yaya-git

'mysql' => array(
        'driver'    => 'mysql',
        'host'      => '127.0.0.1',
        'database'  => 'blog',
        'username'  => 'root',
        'password'  => 'secret',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',

    ),

In the password field you need "secret" you can read more about the credentials here http://laravel.com/docs/homestead#daily-usage

Also if your running environments and for some reason laravel doesn't see the right one you can call php artisan migrate:install --env="local" you can read more about the environments here http://laravel.com/docs/configuration#environment-configuration

dragonfire1119 avatar Sep 05 '14 04:09 dragonfire1119

when connecting from VM, use user: homestead pasword: secret

huglester avatar Sep 13 '14 06:09 huglester

Make sure you login to the VM and go to the directory for your folder there, I found that using migrate artisan from your host (workstation) it fails because the ports are not correct which is true. because the vm uses 3306, while your host would use 33060. One way around this is to make sure your host is not a "local" environment, and set the main app db config as port 33060, and the local db config which would be used on local evironment (make sure your vm is) it will work.

AbbyJanke avatar Sep 15 '14 00:09 AbbyJanke

After much gnashing of teeth I was able to solve the problem by adding the port to the host parameter in the mysql array in config/database.php:

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => '127.0.0.1:33060',
        'database'  => 'homestead',
        'username'  => 'homestead',
        'password'  => 'secret',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ],

thopk avatar Nov 07 '14 20:11 thopk

Set 'host' => "10.0.2.2:33060", and then run artisan migrate from within the VM.

Faiyaz avatar Nov 23 '14 05:11 Faiyaz

Sory, but what if I'm not using any VMs ?

ghost avatar Mar 01 '15 06:03 ghost

@wattay, Can you try editing .env file inside on root folder? I got this issue fixed by changing the database and credentials inside this file. Thanks to @huglester

AlReem avatar Mar 13 '15 04:03 AlReem

Solved just read this http://tutsnare.com/access-denied-for-user-homesteadlocalhost-laravel-5/

Malsayeds avatar Apr 05 '15 03:04 Malsayeds

I get similar error on running aimeos on laravel 5 error: SQLSTATE[28000] [1045] Access denied for user 'justin'@'localhost' (using password: NO)

kashaigili avatar May 03 '15 20:05 kashaigili

go to your root directory , open .env file:

line 5-8: DB_HOST=localhost DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret

you must change dbname ,username ,password.

minahmoghadam avatar May 26 '15 11:05 minahmoghadam

I tried to make changes to database.php file present within config folder it looks something like this

'default' => 'mysql',
....
...
'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'sample'),
            'username'  => env('DB_USERNAME', 'root'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],

I am not using any VM, I am using my local machine, with the database user as root and password a null.

I have also changed my .env file and it looks something like this:

APP_ENV=local
APP_DEBUG=true
APP_KEY=zLzPMzs5W4FNNuguTmbG8M0iFqhIVnsP

DB_HOST=localhost
DB_DATABASE=sample
DB_USERNAME=root
DB_PASSWORD=null

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

Even after doing all the changes when I try to register using the registration form that is shipped with laravel, I try to add a user to my database I get the following error image

In the image we can clearly see that laravel is still trying to connect to homstead database and user, even though I have made changes to all the required places. Can anybody help me in this?

Thanks, Puneet

Update: After doing all the changes I cleared the cache and loaded it again and it seems to work for me now! if any one is also facing the same issue just run the following commands

php artisan cache:clear
php artisan config:cache

puneet0191 avatar Jun 02 '15 05:06 puneet0191

I have similar issues. My database is connected to homestead, with standard .env settings

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

and works with the app in the browser but:

php artisan migrate 

gives the error:

[PDOException]                                                               
  SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (usin  
  g password: YES)   

mmguide2003 avatar Jun 17 '15 08:06 mmguide2003

if you use mysql database : you must change dbname ,username ,password in .env file for example:

DB_HOST=localhost DB_DATABASE=firstapp
DB_USERNAME=root DB_PASSWORD=

or you must use sqlite database.

minahmoghadam avatar Jun 17 '15 17:06 minahmoghadam

I'm using homestead, so my settings are the correct settings for a database in the .env file?. If I use another I won't get the app to work, surely? I have tried and it will not recognise them.

mmguide2003 avatar Jun 17 '15 19:06 mmguide2003

please check the database configuration in the config/database.php file .(Laravel5)

if you are using homestead , so I think that should be like this file ->

'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', '127.0.0.1'), 'database' => env('DB_DATABASE', 'homestead'), 'username' => env('DB_USERNAME', 'homestead'), 'password' => env('DB_PASSWORD', 'secret'), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, ],

minahmoghadam avatar Jun 18 '15 13:06 minahmoghadam

I think you should ssh to your homestead and check if everything is working fine.

zaheen avatar Jun 18 '15 16:06 zaheen

php artisan config:clear worked for me :+1: Anyway thanks @Mohamedalsayed

itsazzad avatar Jun 23 '15 02:06 itsazzad

php artisan cache:clear php artisan config:cache

:+1: :100: Thanks @puneet0191

razikallayi avatar Jun 23 '15 09:06 razikallayi

For me clearing the cache doesn't work. My config is:

$ php artisan tinker
>>> config('database.connections.mysql');
=> [
       "driver"    => "mysql",
       "host"      => "localhost",
       "database"  => "homestead",
       "username"  => "homestead",
       "password"  => "secret",
       "charset"   => "utf8",
       "collation" => "utf8_unicode_ci",
       "prefix"    => "",
       "strict"    => false
   ]

If I ssh to the Homestead, I can log in to the mysql with this command:

mysql -u homestead -p homestead

using the 'secret' password.

UPDATE I missed a small detail from the docs. It says that the migrate command should be run from within the VM. That way it works. I was trying to run the command on the host machine where I have a mysql running too. That's why I got the access denied error instead of the connection problem message.

robertzelic avatar Jun 25 '15 18:06 robertzelic

i had this error before , and i have found the solution , just try to clean up you artisan like this :

php artisan cache:clear php artisan config:cache

just it :)

medamineDev avatar Aug 05 '15 11:08 medamineDev

I had this exact problem and I solved it this way: go into the .env and change the host, database, user,password as follows: DB_HOST=localhost DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD=

now use these exact configurations in your database.php it will work just fine

hussain74 avatar Aug 14 '15 08:08 hussain74

give this error....

[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (usin
g password: YES)

screenshot 2015-08-22 04 35 06

ghost avatar Aug 21 '15 22:08 ghost

Make sure that when running it you are running it on the homestead server. Because your local machine cant connect to the homestead virtual host.

On August 21, 2015 at 6:37:31 PM, lincon sarker ([email protected](mailto:[email protected])) wrote:

give this error....

[PDOException]

SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (usin

g password: YES)

— Reply to this email directly or view it on GitHub(https://github.com/JeffreyWay/Laravel-4-Generators/issues/348#issuecomment-133580839).

Abby Janke

AbbyJanke avatar Aug 21 '15 22:08 AbbyJanke

I think this will fix the problem http://stackoverflow.com/a/32682419/458204

AmrMekkawy avatar Sep 20 '15 17:09 AmrMekkawy

This work for me

  1. Type hostname in your terminal and hit Enter key. This will let you know your hostname (Name of your computer/machine).
  2. Set your DB_HOST In your .env file with your hostname printed as result of step 1

Taking this as references: Source

jorwan avatar Mar 19 '16 01:03 jorwan

SOLVED: i have the same problem then i checked my database in phpmyadmin then i found out that the database from my phpmyadmin is named "test" and the codes from my . env is DB_DATABASE=kervie. so i changed kervie to test and it work.

spooky24kervie avatar Jun 01 '16 06:06 spooky24kervie

i had the same problem what i did is restarting the server (i am using the default server : php artisan serve)

souleima avatar Mar 24 '17 15:03 souleima

i had the same problem, so i use below artisan commands php artisan cache:clear php artisan config:clear php artisan config:cache my problem get resolved using this

Monika252 avatar Jan 02 '18 07:01 Monika252

I ran into this error and my solution and clearing the cache did help. Also, I was using PDO for the first time and my query was something like this...

Route::get('/insert', function(){ DB::insert('insert into posts(title, body)values(?, ?)', ['php is great!', 'I love Laravel']); });

My second error was that I didn't separate the title and the body values to be inserted with a COMMA. Hope it helps any one.

jondisla avatar Sep 26 '18 17:09 jondisla

I ran into this problem as well while following the tutorial (MVC). Thought I would post comment. Solution with cache and config artisan commands fixed.

wyattbiker avatar Oct 15 '18 14:10 wyattbiker

I am having this same problem trying to run homestead database:

[PDOException] SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (usin g password: YES)

I have tried everything on this page. Even tried changing DB_HOST to 192.168.10.10. Still cannot php artisan migrate without error. Any other solutions?

RillistikPete avatar Nov 05 '18 23:11 RillistikPete

check your config/database.php maybe changed user name and password

OmidAhmadyani avatar Mar 14 '19 07:03 OmidAhmadyani

I was getting this too and fixed it by running migrate from vagrant.

  • ssh into vagrant
  • cd /var/www/MySite
  • php artisan migrate

You can also try clearing the cache/config from here too.

I resolve the issue by clearing cache and config and now I can register the user in laravel but it continuously declining to login in auth by this error "These credentials do not match our records.". I had a cross check the database user is registered.

VipinS744 avatar Apr 21 '19 17:04 VipinS744