JeffreyWay / Laravel-4-Generators

Rapidly speed up your Laravel workflow with generators
https://packagist.org/packages/way/generators
MIT License
27 stars 8 forks source link

Access denied for user 'homestead'@'localhost' #348

Open yaya-git opened 10 years ago

yaya-git commented 10 years ago

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)

SilverPaladin commented 10 years ago

Check your database login credentials On 3 Jul 2014 12:49, "yaya-git" notifications@github.com 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.

yaya-git commented 10 years ago

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'    => '',

    ),
SilverPaladin commented 10 years ago

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" notifications@github.com 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 .

DerrickJames commented 10 years ago

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!

dragonfire1119 commented 10 years ago

@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

huglester commented 10 years ago

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

AbbyJanke commented 10 years ago

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.

thopk commented 10 years ago

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'    => '',
    ],
Faiyaz commented 9 years ago

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

ghost commented 9 years ago

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

AlReem commented 9 years ago

@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

Malsayeds commented 9 years ago

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

kashaigili commented 9 years ago

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

minahmoghadam commented 9 years ago

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.

puneet0191 commented 9 years ago

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
mmguide2003 commented 9 years ago

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)   
minahmoghadam commented 9 years ago

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.

mmguide2003 commented 9 years ago

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.

minahmoghadam commented 9 years ago

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, ],

zaheen commented 9 years ago

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

itsazzad commented 9 years ago

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

razikallayi commented 9 years ago

php artisan cache:clear php artisan config:cache

:+1: :100: Thanks @puneet0191

robertzelic commented 9 years ago

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.

medamineDev commented 9 years ago

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 :)

hussain74 commented 9 years ago

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

ghost commented 9 years ago

give this error....

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

screenshot 2015-08-22 04 35 06

AbbyJanke commented 9 years ago

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 (notifications@github.com(mailto:notifications@github.com)) 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

AmrMekkawy commented 9 years ago

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

jorwan commented 8 years ago

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

spooky24kervie commented 8 years ago

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.

souleima commented 7 years ago

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

Monika252 commented 6 years ago

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

jondisla commented 6 years ago

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.

wyattbiker commented 6 years ago

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.

RillistikPete commented 6 years ago

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?

OmidAhmadyani commented 5 years ago

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

chriswright-interconnect commented 5 years ago

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

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

VipinS744 commented 5 years ago

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.