2

I install laravel on Ampps (windows 10) with .

it works.

But Now I want connect to mysql.

I create a 'blog' DB and change these two files: .env file:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD='mysql'

and /config/database.php :

  'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'blog'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', 'mysql'),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],

but still I get the below message when I want to migrate:

C:\Program Files (x86)\Ampps\www\blog>php artisan migrate

[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = blog and table_name = migrations)

[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)

1
  • 1
    Please include the error message instead of posting a screenshot. Commented Apr 16, 2017 at 21:12

4 Answers 4

1

Password should be this

DB_PASSWORD=mysql

Not this

DB_PASSWORD='mysql'
Sign up to request clarification or add additional context in comments.

1 Comment

It worked for me on namecheap. thanks
1

You should write this

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

and your env file is

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD=mysql

Also restart your server.

Comments

1

First change your password in .env file from DB_PASSWORD='mysql' to DB_PASSWORD=mysql without single quotation. Second you should set more secure passwords for your databases.

You should give root user access to your database.

GRANT ALL PRIVILEGES ON blog.* TO 'root'@'localhost' identified by 'mysql';
FLUSH PRIVILEGES;

1 Comment

This was it for me. I changed servers and the db user could read and write but not alter tables.
0

Try running below command

php artisan cache:clear

This should update the settings saved in the cache.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.