I have installed Laravel 5 successfully and changed MySQL credentials in database.php file in config directory to '
mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'wdcollect'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
I don't want to use homestead and I have changed .env file to
APP_ENV=local
APP_DEBUG=true
APP_KEY=apLIzEMOgtc5BUxdT9WRLSvAoIIWO87N
DB_HOST=localhost
DB_DATABASE=wdcollect
DB_USERNAME=root
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
I don't understand that why it's saying that access denied for 'homestead'@'localhost'
Match the .env file and the config.php file with your username and password and your hostname in the database settings.if they are not equal,relation will not connect.
You do not need to set credentials in database.php file. It is enough if you have credentials in .env
If you are able to login to database directly then this password must work. It can be possible that you are having different environment than "local" which is defined in this file. Test is with "php artisan env"
Try to checkout the ".env" file in your root directory. It will be a hidden file. Correct these values.
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
In my case, it was actually root user permission problem. My Laravel
configurations were all perfect, but later I found that it was root user permission problem since my MySQL configs were somehow changed.
skip-grant-tables
in following place:[mysqld] skip-grant-tables port=3306
and it worked.
Edit the file .env in your laravel root directory. make looks as in below :
DB_HOST=localhost
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=your-root-pas
Also create one database in phpmyadmin named, "laravel".
Run below commands :
php artisan cache:clear
php artisan config:cache
php artisan config:clear
php artisan migrate
It worked for me, XAMPP with Apache and MySQL.
Reason is the old database credentials are cached /bootstap/cache/config.php
In the .env file, I modified it as follow
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Then removed that file
/bootstap/cache/config.php
If the issue still there you might try the following.
php artisan config:clear php artisan cache:clear php artisan config:cache
Exit vagrant by writing the exit
command
Then restart vargarnt/homestead config
vagrant reload --provision
Then opened vagrant again
Vagrant Up
Vagrant ssh
Jeez! Thanks to umair.ashfr answer here below, I finally hit the nail with an issue that was eating my neurons.
I had a password like DB_PASSWORD=ffjdh5#fgr on my .env, and MySQL connection was gracefully saying that "SQLSTATE[HY000] [1045] Access denied for user...", no matter what flavor of php artisan I was trying to run.
The problem was that "#" sign inside the password. BEWARE! That means the start of a comment, thus my password was silently truncated! The solution is to declare password like DB_PASSWORD="ffjdh5#fgr"
Regards
You need to run these two commands
php artisan cache:clear
php artisan config:cache
If you are on MAMP
Check your port number as well generally it is
Host localhost
Port 8889
User root
Password root
Socket /Applications/MAMP/tmp/mysql/mysql.sock
The .env file should have same database name , username and password as in the mysql database and check whether all permissions are granted to the user for accessing the database or not. I solved my problem by adding the cpanel username in front of database name and username like jumbo_admingo and jumbo_user1 respectively where jumbo is my cpanel username and admingo is the database name i created in mysql and user1 is the user which has been provided the access to the database admingo. THIS SOLVED MY PROBLEM.
Please update below file.
vendor - .env - on line#7
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Instead of homestead user your database, username and password. This should work for you.
This works to me:
php artisan config:clear
php artisan cache:clear
php artisan config:cache
Thanks.
I had the same problem, so I realized that the .env
file does not accept special characters, as my password has these characters, I added the password in the config/database.php
file.
None of these worked for me when I deployed my website online on shared hosting, below is what I did that worked.
In the .env
file, I changed
DB_HOST=127.0.0.1
to
DB_HOST=localhost
and viola, it worked well as expected.
I Faced Same Problem what i did
but Same problem found than i run this artisan command
php artisan view:clear
Hope it will helpful.
I was facing the same issue. Everything was fine but in
bootstrap/cache/config.php
always had the incomplete password. Upon digging further, realized that the password had '#' character in it and that was getting dropped. As '#' is used to mark a line as a comment.
if you before use localhost and root your file be cached
remove /bootstap/cache/config.php
Instead of using this
DB_HOST=localhost
DB_DATABASE=wdcollect
DB_USERNAME=root
DB_PASSWORD=
USE this
DB_HOST=localhost
DB_DATABASE=wdcollect
DB_USERNAME=root
DB_PASSWORD=''
I came up with this too... then I solve it by putting the database information directly in " database.php " In your case, I would change the information like this
mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'wdcollect',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
and don't forget to change your setting in XAMPP's config.inc
['auth_type'] = 'config';
['Servers'][$i]['user'] = 'root';
['Servers'][$i]['password'] = '';
['AllowNoPassword'] = true;
I spent hours on this :-( and finally, it was really easy to hack
BEFORE
DB_PASSWORD=#Root2020$
UPDATED
DB_PASSWORD="#Root2020$"
I think the problem was # in the password, that's why I had to write my password into quotation marks.
Declare password like DB_PASSWORD="2o0@#5TGR1NG" in .env file
If # sign include in your password then password will declare in between " ".
Pls Update .env file
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
After then restart server
Source: Stackoverflow.com