Sylvain Attoumani Sylvain Attoumani - 2 years ago 140
MySQL Question

Access denied for database in laravel

I'm just beginning at Laravel and I have some issue with the database. I tried to make a php migrate and got the following error :

enter image description here

here is my database.php file :

[...]
'default' => env('DB_CONNECTION', 'mysql'),
[...]

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


and my .env :

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=33060
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD='password'

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

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

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=


I tried several things like replace
localhost
by
192.168.10.10
or
127.0.0.1
in my .env but I still have an error. I also tried to do :
mysqladmin -u homestead -p status Enter password: secret
but It doesn't work, they ask for a password and no matter what I put, they tell me
error: 'Access denied for user 'homestead'@'localhost' (using password: YES)'

Answer Source

change this variables

DB_HOST=localhost
DB_DATABASE="dataBaseName"
DB_USERNAME="root"
DB_PASSWORD=


note: that username is default to root and password to empty
then run : php artisan migrate
it should work

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download