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:
The Users in Mysql:
Databases:
Error:
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.
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
Try in your env:
DB_PASSWORD= 'YourPassword'
Related
I am building a basic CRUD app using Laravel 7 Homestead in a Vagrant VM. The root address http://crud-app.local.test works, but when I add a defined route (http://crud-app.local.test/cats) I get this error page:
Error message in browser when navigating to '/cats' route.
So far I have:
Verified my MySQL password matches in the .env file and in practice
Changed the MYSQL password so that it's no longer empty (and made sure it matches what's in the .env file)
Ran php artisan config:cache
Ran php artisan config:clear followed by php artisan cache:clear
Changed 127.0.0.1 to localhost
Made sure the database defined in the .env file exists (crud)
Ran php artisan migrate (no errors, and the cats table exists in the crud database)
Restarted and re-provisioned the machine (vagrant reload --provision)
I'm at a loss now.
Make sure that you give "root" permissions to read from the database that you've created. As it's root#localhost rather than root#127.0.0.1 sometimes mysql differentiates. Just check the permissions that root#localhost has for the database and if you update them, flush the privileges.
Can't able to connect database in only laravel 7
my url is http://localhost:8000/index
Here is my project .env file
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=amazon_services
DB_USERNAME=root
DB_PASSWORD=""
i have run the following commands but still facing error
php artisan config:cache
php artisan config:clear
php artisan cache:clear
But i can able to connect the database in laravel 5.4 version while using url like this http://localhost/larave/laravel5.4/inde but while using laravel 7 with development server not connected
This probably is permission error by mySql.
If you are using root as username with no password please add user privileage to the database table you are connecting to like below.
Furthermore you will also need to grant access to root user to perform specific action on table.
And then
If the above solution did not work for you try following
php artisan config:cache
php artisan config:clear
php artisan cache:clear
Keep your .env file as
DB_USERNAME=root
DB_PASSWORD=
Open .env and change that :
DB_HOST=127.0.0.1
DB_PASSWORD=
If the problem persists, try logging into mysql yourself.
when typing the command php artisan migrate, it is giving me an error:
Illuminate\Database\QueryException : SQLSTATE[HY000] [1049] Unknown
database 'proj' (SQL: select * from information_schema.tables where
table_schema = proj and table_name = migrations and table_type = 'BASE
TABLE')
Although, i edited the .env file and i had created the database proj and restart the cmd and also i tried
php artisan config:cache
and similar commands but still not working
view error image
phpmyadmin view
.env file view
This means that you don't have this database created. First create the database and after run: php artisan migrate:fresh to create the tables.
By the screenshots you have uploaded, you have many servers. Check the port of the server mysql and change the port on the .env file. This will work.
Open the .env file and edit:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // db Name
DB_USERNAME= // db Username
DB_PASSWORD= // db Password
Run below commands:
php artisan config:cache
php artisan migrate
I hope this will help you
I transferred a Laravel project based on moving Laravel project between computers
Everything was fine at the first look. I could install the composer without any problems, then I set my environmental variables in my .env such as database name, database user and so on.
When I started using the following command,
php artisan cache: clear
I got these two errors,
In Connection.php line 664:
SQLSTATE[HY000] [1045] Acess denied for user 'root'#'localhost' (using password: Yes) (SQL: select * from information_schema.tables where tabale_schema = *** and table_name = ****)
In Connector.php line 67:
SQLSTATE [HY000] [1045] Access denied for user 'root'#'localhost' (using password: Yes)
Further Information:
It seems .env has not been read by the application because when I browse the homepage of the app, I got Whoops error which shows environmental variable is empty.
I tested my database connection such as its username, password, and other parameters, I know they are working properly.
In the end, I attached a photo in order to elaborate on the issue.
Interestingly, in my .env file, DB_DATABASE value is "nlp" and DB_USERNAME equals "Javad" but as you can see in the errors, they are not working, and the Artisan assumes the root as the user!
After you move a Laravel project to another location, The first thing you have to do is regenerate APP_KEY in the .env file by running the command from your application root directory:
php artisan key:generate
After that, you reconfigure your cache:
php artisan config:cache
Additionally, make sure all your database parameters in your .env file and config/database.php are correct and the same as your previous Laravel setup - You can change them manually and then reconfigure your cache as shown above. If not (for instance, the database name is changed), you may have to rerun your database migrations and seeders again:
php artisan migrate
and
php artisan db:seed
I think the configuration files are not writable by the apache user, considering you are using apache. Make sure you have given write permission to bootstrap/cache for the user. This directory contains the cached configuration files.If that is the case the congratulations will be loaded from here and your previously used configuration will be loaded which may be causing the issue.
Also you need to give write permission to the storage directory too. As there is the log file and apache user needs to write on that too.
Step 1: Go to the project path project_name\bootstrap\cache folder and remove the marked file config.php from the mentioned folder.
Step 2: Run the following command
composer dump-autoload
php artisan clear-compiled
php artisan config:clear
php artisan cache:clear
php artisan config:cache
I hope that it will work now!
Open the .env file and edit it. Just set up correct DB credentials:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // Your Database Name
DB_USERNAME= // Your Database Username, If no username has been set then by default there is a root as a username
DB_PASSWORD= // Your Database Password, If no password is set on the database, clear it
After completion of .env edit please enter this command in your terminal for clear cache:
php artisan config:cache
If there is still the same error then try another possible solution.
I had also face the same problem, I tried all the possible answers in StackOverflow but nothing could help me, this solution worked on the first try:
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.
I found this solution from here laravel.io (Read the solution of Byjml)
I've been trying to get data from my database in laravel 5.7.3, but it seems to be using the wrong database name, username and password as it returns this error:
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from `tasks`)
My .env file database section is also according to my needs and set like this:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mrdb
DB_USERNAME=root
DB_PASSWORD=
PS: My app environment is still local. I can also migrate and put in data into database with artisan tinker without issues, but cannot just fetch data from the database.
The only way it gets to work is to change config/database.php mysql section to my parameters, which I believe it isn't just right.
Why is the .env not wanting the change when the database is called?
Laravel uses caching to speed up your sites loading times, one of the things laravel caches is the config files located in the config/ directory. Most of these files do have references to the .env file by using the env() helper function.
One can create a config cache by using php artisan config:cache which will then be stored in bootstrap/cache/config.php.
To remove this specific cache you can use php artisan config:clear, to clear all cache use php artisan cache:clear.
This is cache issue use these commands
php artisan cache:clear
php artisan config:cache
After that delete all cache file ie inside
storage/framework/views