Skip to content
Advertisement

Access denied for user ‘homestead’@’localhost’ (using password: YES)

I’m on a Mac OS Yosemite using Laravel 5.0.

While in my local environment, I run php artisan migrate I keep getting :

Access denied for user ‘homestead’@’localhost’ (using password: YES)

Configuration

Here is my .env

APP_ENV=local
APP_DEBUG=true
APP_KEY=*****

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

appconfigdatabase.php

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

How do I avoid this kind of error ?

I’ve tried :


1

in app/database.php

Replace localhost with 127.0.0.1

'host'=> env('DB_HOST', 'localhost') –>'host' => env('DB_HOST', '127.0.0.1')

Also, in .env

DB_HOST=localhost –> DB_HOST=127.0.0.1


2

Try specify environment

php artisan migrate --env=local


3

Check to see if the MySQL is running by run

mysqladmin -u homestead -p status Enter password: secret

I got

Uptime: 21281 Threads: 3 Questions: 274 Slow queries: 0 Opens: 327 Flush tables: 1 Open tables: 80 Queries per second avg: 0.012

Which mean it’s running.


4

Check MySQL UNIX Socket (This step work for me)

Advertisement

Answer

Check MySQL UNIX Socket

Find unix_socket location using MySQL

mysql -u homestead -p

mysql> show variables like '%sock%';
+-----------------------------------------+-----------------------------+
| Variable_name                           | Value                       |
+-----------------------------------------+-----------------------------+
| performance_schema_max_socket_classes   | 10                          |
| performance_schema_max_socket_instances | 322                         |
| socket                                  | /var/run/mysqld/mysqld.sock |
+-----------------------------------------+-----------------------------+
3 rows in set (0.00 sec)

Then I go to config/database.php

I update this line : 'unix_socket' => '/tmp/mysql.sock',

to : 'unix_socket' => '/var/run/mysqld/mysqld.sock',

That’s it. It works for my as my 4th try.I hope these steps help someone. 😀

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement