I am creating my very first project and I want to use my local php environment instead of Hemestead.
I created the project and now I have to create the database. I'mtrying to follow the steps of this link "https://laravel.com/docs/5.1/quickstart" and want to execute this command: php artisan migrate.
When executing I take this error:
Access denied for user 'homestead'#'localhost' (using password: YES)
I read this: Access denied for user 'homestead'#'localhost' (using password: YES)
but I don't understand something. What to put instead of:
DB_HOST=yourHostName
DB_DATABASE=yourDatabaseName
DB_USERNAME=yourDatabaseUsername
DB_PASSWORD=youPassword
So how to find my database name, hostname etc?
I repeat I am not using Homestead.
Please be sure that you have homestead db in your phpmyadmin. If don't, please create a new one. And than, go to .env file (this is the default of mysql) fill your username database with root, and the password is (empty). I had a same problem with you about 1 or 2 months ago. I just created a new one db because I have no homestead db in my phpmyadmin. I hope this helps.
If you did not change anything in your homestead configuration, those are the values
DB_HOST=localhost
DB_DATABASE=homestad
DB_USERNAME=homestad
DB_PASSWORD=secret
If you are not sure about it, SSH into your homestead box and try to login using
mysql -uhomestead -psecret
Also try
mysql -uroot -psecret
And if it works you have to change them to
DB_HOST=localhost
DB_DATABASE=homestad
DB_USERNAME=root
DB_PASSWORD=secret
If it doesn't login, you probably will have to recover your MySQL password:
http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
Related
I'm trying to access a database (which exists on a different server) on my Laravel application. I keep getting the following error: SQLSTATE[HY000] [2002] Permission denied
My .env file is set up as follows (changed a bit to protect privacy):
DB_CONNECTION=mysql
DB_HOST= IP_ADDRESS
DB_PORT=3306
DB_DATABASE=DB_NAME
DB_USERNAME="laravel_user"
DB_PASSWORD="password"
I'm not sure if this is important or not but I can access the web server's database if I go to the link IP.ADDRESS/phpmyadmin
My web.php file is as follows:
Route::get('/test', function(){
return DB::select("select * from umts_list");
});
Additionally, I also went to IP_ADDRESS/phpmyadmin (where my database exists) and added a new user called laravel_user with the ability to SELECT all data and saved it with the 'password' as its password.
My attempt: I tried whatever I mentioned above and also cleared the cache since I made changes to the .env file by entering the following commands:
php artisan config: clear
php artisan cache: clear
Any help would be appreciated. Thank you.
Edit 1: On phpMyAdmin, I made sure to add the user as depicted by the following picture:
PhpMyAdmin User Account
Additionally, I also checked the port number on phpMyadmin and it is 3306 as depicted by the following image:
Port Number
just in case anyone else stumbles upon this post in the future, it turns out that I did not have to create an SSH tunnel or whitelist the IP. The problem was actually with SELinux. This post was the solution: Laravel permission denied on remote Mysql server (AWS aurora)
Specifically, I ran the command: sudo setsebool -P httpd_can_network_connect_db=1
This worked perfectly and it was actually blocking connection to remote databases.
I upload my project on C-panel and set my connection for database in my env file, it was ok for me with the same settings, but now i don't know why it's happening, this is error :
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO) (SQL: select *
from `permissions`)
And this is my env file settings for database :
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=thermota_db
DB_USERNAME=thermota_user
DB_PASSWORD= { my password }
i don't know this permissions in error, is my permissions_table ?
and why error for this table ?
Multiple reasons can be the cause.
This can happen when the server has already been started before updating database details on your .ENV file.
It could also be from inputting wrong database authentication details.
Solution
Restart the server anytime you update values on your .ENV file.
Ensure you use the correct authentication details or better still create a new database user.
Run this command:
php artisan config:cache
You are trying to use a different user that means that your root value is not used.
You need to cache your env field to use the values in it. That goes for every change you make as well.
if ur on online server do the following steps :
1 - locate to : /vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php
2 - add thoes line of code on the begining of this function : createConnection($dsn, array $config, array $options)
3 - code to add : \Artisan::call('config:cache');
4 - refresh ur home page
5 - remove the "\Artisan::call('config:cache');" line code
6 - enjoye ^^
I had the same issue and I couldn't run config:cache artisan command even with
Artisan::call('config:cache');.
So I done this and solved my issue:
artisan config:cache caches all files from /config into a single array that it stores. It then reads all config variables from that array and ignores anything in .env or the /config files until you recach them. That's why it still works after deleting .env.
https://laravel.com/docs/5.6/configuration#configuration-caching
If you don't have ssh access to your live server, you'd just need to delete the bootstrap/cache/config.php file, which is the cache file config:cache generates.
I'm trying to run php artisan migrate on my Laravel project but I keep getting SQLSTATE[HY000] [1045] Access denied
for user 'app'#'localhost' (using password: YES). I created a python test program to connect to the database with the exact same info and it works, so I know the details are correct.
If you need it, info in .env:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=8889
DB_DATABASE=testapp
DB_USERNAME=app
DB_PASSWORD=123abc
Have I missed a step? Thanks in advance for your help! <3
The error is due to the credentials, was the application serving before you updated the .env?
If it was you will need to run in the console:
php artisan config:clear
This will then re-read the .env file.
I'm getting this error when I open a view that requires data:
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from `books`)
I created the homestead#localhost user in MySQL with the specified password, but I'm still getting the error... What might cause this and how can i fix it? Thanks! :) (I already tried restarting the php artisan serve process and running php artisan config:clear...)
This is really stupid but Laravel was lying about the password it was using; it was actually "secret" as defined in the .env file!
I just used artisan migrate to create some table, but I get an error of Type PDO:
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO)
A php/mysql testscript could connect to the database just fine, but it was another virtualhost and it did not use PDO.
In Laravel4 edited app/config/local/database.php to set the password and database name.
edit in start.php
UPDATE
I hardcoded the password in the PDO connection array and now terminal says there is no database named "database". Clearly it is looking somewhere else for the config, but I have no other config file.
(Due to following a tutorial about making a "local" directory it was not working for me)As it stands, I have downloaded the stable version and everything is working great.
I am going to delete this post, to keep the forum clean.
Make sure you have set up your database connection correctly in app/config/database
Laravel Database Docs
Make sure you are setting up a 'local' environment in start.php
Otherwise Laravel will look for DB config in app/config/database.php
Kindly Check Your app/config/database.php file in local host.
1.)Make Sure local Host Data Base name is Correct
2.)Make sure local Host Data Base username is correct.
3.)Make sure local Host Data Base password is correct.