0

I'm having problems to create database tables.

First of all I create the models:

php artisan make:model Company -m

Second I update the migration company file, adding the columns that I need

Third I'm going to phpMyAdmin and create a new database named test

Fourth I run the command php artisan migrate or php artisan migrate:install and I have the next error:

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

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

In database/config.php I edit the mysql driver to this:

'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'test'),
        'username' => env('DB_USERNAME', 'root'),
        'password' => env('DB_PASSWORD', 'pass'),
        'charset' => 'utf8',
        'collation' => 'utf8_general_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

And .env file:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=pass

I also tried to clean cache with php artisan config:clear .

Anyone can help me? I don't understand what is the problem.

Thank you

user3242861
  • 1,839
  • 12
  • 48
  • 93

2 Answers2

0

Your "root" password is incorrect or it may not have required permissions.

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

Reset "root" password:

https://www.howtoforge.com/setting-changing-resetting-mysql-root-passwords

Grant "root" user privileges:

Ubuntu: https://www.liquidweb.com/kb/how-to-add-a-user-and-grant-root-privileges-on-ubuntu-14-04/

Centos: https://www.liquidweb.com/kb/how-to-add-a-user-and-grant-root-privileges-on-centos-7/

Then try again :)

Update for the OP ( OSX ):

Setting the MySQL root user password on OS X

Mecanik
  • 1,539
  • 1
  • 20
  • 50
0

in config/database.php file edit the password field to "password' => env('DB_PASSWORD', ''), and in .env file DB_PASSWORD = keep the field as empty as given here

Mutasim Fuad
  • 606
  • 2
  • 12
  • 31