0

I accidentally deleted the database for my project so I am trying to recreate all those tables using php artisan migrate.

I can log into MySQL with mysql -u root -p and then I enter in the password of "password" which will allow me to see all my databases. Since I deleted my database I created another database "endorsify_dev" using Create Database endorsify_dev sql command.

Then, I went to do php artisan migrate, but that gave me an error that I cannot figure out.

My .env file:

env


The Users in Mysql:

users


Databases:

database


Error:

error

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
Jennifer Zhou
  • 323
  • 1
  • 7
  • 20
  • 1
    In addition to the answer below, you may need to grant privileges for that database to the root@localhost user. In the mysql cli `GRANT ALL PRIVILEGES ON endorsify_dev.* to 'root'@'localhost'; FLUSH PRIVILEGES;` – Chris White Apr 24 '19 at 17:38
  • just forgot about root or all . some time its happen so just create new user and password with all are granted than create new database or changed all configuration from .env file....... just follow these steps for new users ------------- 1 - CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'newpassword'; ------- 2 - GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost'; or last step - FLUSH PRIVILEGES; – Krishna kushwaha Apr 25 '19 at 07:29

3 Answers3

0

You connected yourself with mysql cli clent as root and with a password. But you PHP error indicated (using password: NO).

I assume your php code (Connection.php and PDOConnection.php) is trying to connect to the mysql database without using DB_PASSWORD provided in your .env file.

antoine.lange
  • 731
  • 6
  • 24
0

This error basically comes from changing .env file values.

SQLSTATE[HY000] [1045] ACCESS denied for user 'root'@'localhost' (using password: NO)

Your .env file configuration should be something like this:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=endorsify_dev      // Your Database Name
DB_USERNAME=root              // Your Database Username
DB_PASSWORD=                 // Your Database Password

NOTE: If no password is set on the database, clear it DB_PASSWORD, empty space must also be removed

If All is correct then After completion of .env edit, You can clear the configuration cache with the following artisan command: php artisan config:cache

Also, check in config/database.php, Check that the old database name has not been used on it.

Also, If you are using the PHP's default web server (eg. php artisan serve) you need to restart your server after changing your .env file values

To run all of your outstanding migrations, execute the migrate Artisan command:php artisan migrate

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
0

Try in your env:

DB_PASSWORD= 'YourPassword'