Access denied - Laravel/MySQL [duplicate] - php

This question already has answers here:
MySQL ERROR 1045 (28000): Access denied for user 'bill'#'localhost' (using password: YES)
(43 answers)
Closed 2 years ago.
When i try to go on my app, i have this message :
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost'
But when i make php artisan migrate, that work and tables are create on my local database ...
When i open mysql, i have :
Service : Mysql#localhost:3306
User : root
Password : ****
and my .env
APP_NAME=Laravel
APP_ENV=development
APP_KEY=**********************************
APP_DEBUG=true
APP_URL=localhost
TELESCOPE_ENABLED=true
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=mydatabase
DB_USERNAME=root
DB_PASSWORD=root

You need to set a permission:-
try: GRANT ALL PRIVILEGES ON * . * TO 'your_user'#'localhost';
The error on your site now is the permission denied.

Related

Environment variables declared in shell are not being read in my .env file

Using Windows 10
php bin/console make:migration
In AbstractMySQLDriver.php line 112:
An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'db_user'#'localhost
' (using password: YES)
In Exception.php line 18:
SQLSTATE[HY000] [1045] Access denied for user 'db_user'#'localhost' (using password: YES)
In PDOConnection.php line 39:
SQLSTATE[HY000] [1045] Access denied for user 'db_user'#'localhost' (using password: YES)
.env file
DATABASE_URL="mysql://db_user:db_password#127.0.0.1:3306/db_name?serverVersion=5.7"
I tried defining my environment variables both from inside my shell as well as inside .env file
set db_user=root
set db_password=12345678
set db_name=loremipsum
The only way I got this to work was by hardcoding my variables like so:
DATABASE_URL="mysql://db_user:db_password#127.0.0.1:3306/db_name?serverVersion=5.7"
I am not running a virtual environment.
From what you pasted, it seems like your .env file does not contain you DB connection information.
The DATABASE_URL in your .env file should contain all of the connection information. There is no interpretation of you shell env variable in there. Therefore, it will not translate db_user to "root" in the .env.
For example, your.env should look like this. You can omit the double quotes too in the .env
DATABASE_URL=mysql://root:12345678#127.0.0.1:3306/loremipsum?serverVersion=5.7
Maybe you don't like having your credentials stored in that file. Symfony has a solution for you, secrets. https://symfony.com/doc/current/configuration/secrets.html
Basically, secrets will generate a decryption key for you .env files. Therefore you only need to secure the decryption key and be able to version control your .env files.

How can I fix this error ( Laravel 5.7 )?

When I try to login ?
Illuminate \ Database \ QueryException (1045) SQLSTATE[HY000] [1045]
Access denied for user 'homestead'#'localhost' (using password: YES)
(SQL: select * from users where email = andro.nady2015#gmail.com
limit 1)
Please try this:-
DB_HOST=127.0.0.1
in place of this:-
DB_HOST=localhost
thanks everyone , I solved this problem by download new version of Xampp

php artisan key:generate does not generate key [duplicate]

This question already has answers here:
Access denied for user 'homestead'#'localhost' (using password: YES)
(32 answers)
Closed 4 years ago.
When I try to run " php artisan key:generate " I get the following error in promptScreenshot of the error
Actually I am running a laravel project on different laptop. I am having this issue while generating a key. How can I solve it?
Error In Connection.php line 647: SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = homestead and table_name = permissions) In PDOConnection.php line 47: SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) In PDOConnection.php line 43: SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
Just put Your system's database configuration in .env file. Like Database name user and password.

Laravel/Doctrine randomly tries to connect to production database

I'm randomly getting server errors because Laravel is trying to connect to the production database, despite the fact that I have a .env file set up and a majority of the time it connects to the correct database.
Here is the error I am receiving:
[2018-02-17 08:05:54] production.ERROR: SQLSTATE[HY000] [1045] Access denied for user 'forge'#'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = forge and table_name = settings) {"exception":"[object]
(Illuminate\\Database\\QueryException(code: 1045): SQLSTATE[HY000]
[1045] Access denied for user 'forge'#'localhost' (using password: NO)
(SQL: select * from information_schema.tables where table_schema = forge and table_name = settings) at C:\\wamp64\\www\\projects\\infusedx\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:664,
Doctrine\\DBAL\\Driver\\PDOException(code: 1045): SQLSTATE[HY000]
[1045] Access denied for user 'forge'#'localhost' (using password: NO)
at
C:\\wamp64\\www\\projects\\infusedx\\vendor\\doctrine\\dbal\\lib\\Doctrine\\DBAL\\Driver\\PDOConnection.php:47,
PDOException(code: 1045): SQLSTATE[HY000] [1045] Access denied for
user 'forge'#'localhost' (using password: NO) at
C:\\wamp64\\www\\projects\\infusedx\\vendor\\doctrine\\dbal\\lib\\Doctrine\\DBAL\\Driver\\PDOConnection.php:43)
Why would doctrine be trying to connect to the wrong database? Is it being insantiated before dotenv sometimes?
First
You can try clear or re-cache your configurations
php artisan config:clear or php artisan config:cache
before running your migration commands
Secondly
I had this issue on heroku. When trying to run migration commands from heroku's ssh heroku ps:exec environment. i was doing:
heroku ps:exec
and
php artisan migrate
but the env variables set in the heroku app isn't available to laravel (env('DB_DATABASE'), etc).
To fix this, i had to run the migrations from the bash
heroku run bash
then
php artisan migrate

Access denied for user ‘dbuser’ [duplicate]

This question already has answers here:
Access denied for user 'homestead'#'localhost' (using password: YES)
(32 answers)
MySQL: Access denied for user 'test'#'localhost' (using password: YES) except root user
(18 answers)
Closed 5 years ago.
In order to create a database, I run the command in terminal:
php artisan migrate
I get this:
SQLSTATE [HY00] [1045] Access denied for user ‘dbuser’#‘localhost’ (using password: YES) (SQL: select * from information_schema.table where table_schema = blog and table_name = migrations)
I’ve ran the command php artisan config:cache and it was successful but I still can’t seem to configure phpMyAdmin to connect to database? How can I solve this error?
After making any configuration related changes in .env or to files in config directory,
You need to run:
$ php artisan config:clear

Categories