problems with database connection in laravel 5
Asked Answered
D

8

9

I use the command php artisan migrate to migrate my database connection but I still get the same error and I checked everything, nothing wrong. I used the same connection that I always use in Laravel 4.2

Here is the message I get on my console:

exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)' in C:\xampp\htdocs\Projects\blog\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:47
Defy answered 8/2, 2015 at 1:50 Comment(2)
Please post your database.php with the connection settings (with passwords xxx)Saprogenic
@michael 'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhost'), 'database' => env('DB_DATABASE', 'root'), 'username' => env('DB_USERNAME', ' '), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, ],Defy
S
7

Take a look at your config/database.php and .env file.Maybe your database information is different.

Socher answered 29/5, 2015 at 13:34 Comment(0)
S
20

You need to change the values in your .env file, located in the root folder of your project.

If there is no .env file, copy the .env.example file to .env.

Laravel uses this file to protect your passwords. The values as you are setting those are only used if there is no configuration available in the .env file, homestead is the standard user there.

Saprogenic answered 8/2, 2015 at 2:19 Comment(1)
Wow...! .env file was not visible in my netbeans project (wonder) than find in browser and done.. Thanks...!Rhythmandblues
S
7

Take a look at your config/database.php and .env file.Maybe your database information is different.

Socher answered 29/5, 2015 at 13:34 Comment(0)
H
6

You can go to .env file. File available on Project Root folder.

Then some here related to your database.

enter image description here

Then run below command to clear the old configuration cache.

php artisan config:clear

Heel answered 17/5, 2015 at 8:18 Comment(0)
M
5

Have this problem as well. After update .env and run php artisan config:clear problem still persisted! Then after stoping the server and restart the server again with php artisan serve, problem fixed!

Madeline answered 22/6, 2015 at 18:26 Comment(1)
Run this two command for solving SQLSTATE[HY000] [1049] Unknown database............Lenhard
S
1

I solve this issue by update .env file with config/database.php file.

here is my config/database.php structure (I am using mysql)

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

And .env file structure (same like config/database.php)

 DB_HOST=localhost      // Host name
 DB_DATABASE=larablog   // Database name
 DB_USERNAME=root       // Database User
 DB_PASSWORD=           // Db password(No password here) 
Sherwin answered 8/2, 2015 at 1:50 Comment(0)
A
1

Change the following attribute from database.php

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

to

 'mysql' => [
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'laravel',
            'username'  => 'root',
            'password'  => '',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],

This must work well then run the following command:

php artisan migrate:install
Aeneus answered 3/7, 2015 at 21:14 Comment(0)
D
1

i was getting same error after updating database info in my .env file. fixed the problem exit command prompt and re run php artisan serve command it helped me out and might helpful for you.

Deliquescence answered 8/2, 2017 at 20:4 Comment(0)
S
0

If you're using sqlite as the database, make sure you've php5-sqlite installed

sudo apt-get install php5-sqlite

If it's installed, it might be a problem with your .env file. Replace

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

with this

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
Surratt answered 29/4, 2016 at 10:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.