Laravel PDOException(code: 1045) yet credentials work in phpmyadmin - php

An PDOException(code: 1045) error occurs when laravel connects to mysql yet the credentials allow me to log in via phpmyadmin suggesting the credentials are correct.
Error message:
(PDOException(code: 1045): SQLSTATE[HY000] [1045] Access denied for user 'host.domain.com'#'localhost' (using password: YES)
.env file:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=host.domain.com
DB_USERNAME=host.domain.com
DB_PASSWORD=password_here
PHP version is 7.2.31
Laravel Framework version is 6.13.1
CentOS server (note cant make the error occur on my Windows laptop with WAMP)

If I quoted the DB_DATABASE, DB_USERNAME and DB_PASSWORD fields in .env the application worked. I have no further explanation of why considering there are no spaces in the values for these fields.
Revised .env file:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE="host.domain.com"
DB_USERNAME="host.domain.com"
DB_PASSWORD="password_here"

Related

Problem with DB after cloning project from repo // PHP laravel

I have a problem with my Laravel project. After cloning the repo from git I did
npm install
composer install
php artisan migrate I have an error:
In Connection.php line 664:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost'
(using password: YES) (SQL: select * from languages where status =
1)
In Connector.php line 70:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost'
(using password: YES)
I've added few changes to .env file only
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:q/o7QZeznstW1iBW65t8F7usVPI1oA9osHGaCa6uONU=
APP_DEBUG=true
APP_URL=localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=8889
DB_DATABASE=newDB
DB_USERNAME=root
DB_PASSWORD=root
I am using mamp on mac os for my web environment.
Error Screenshot:
Try adding this to your .env file
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
I use MAMP too and always need this inside my .env files
Open the .env file and edit it.
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:q/o7QZeznstW1iBW65t8F7usVPI1oA9osHGaCa6uONU=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // Your Database Name
DB_USERNAME= // Yout Database Username
DB_PASSWORD= // Your Database Password
NOTE: If no password is set on the database, clear it DB_PASSWORD
This error basically comes from the after changes in the .env file:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost'
(using password: YES)
After completion of .env edit, must be clear cache: php artisan config:cache

How to connect Laravel to MAMP mysql on Mac

Here is my Laravel Database config
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=8889
DB_DATABASE=carnet
DB_USERNAME=root
DB_PASSWORD=root
But i keep getting this error
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost'
(using password: YES)
Try changing the host from localhost to 127.0.0.1 and check if it connects.

Laravel access denied but I can connect using phpmyadmin or normal php query

I'm getting this error message when I try to migrate using artisan
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1045] Access denied for user 'myuser'#'mycomputerip'
(using password: YES) (SQL: select * from information_schema.tables where t
able_schema = database and table_name = migrations)
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'myuser'#'mycomputerip'
(using password: YES)
I have tryed to use my local xampp mysql database and that did also not work.
I'm using mariadb on the server which is the one I'm trying to connect to.
env file (default chagnes bcus security)
DB_CONNECTION=mysql
DB_HOST=serverip
DB_PORT=3306
DB_DATABASE=database
DB_USERNAME=myuser
DB_PASSWORD=mysecurepassword
I am able to connect using a normal php mysqli connection or with phpmyadmin
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=database
DB_USERNAME=myuser
DB_PASSWORD='' or DB_PASSWORD=mypassword
And
php artisan config:clear
and Then Restart Your serve and Then Try it..

Access denied for 'root#localhost' (using password: NO)

I recently installed mac OSX. I installed latest version of mamp.
I was trying to setup my database, but i got this error.
Access denied for 'root#localhost' (using password: NO)
my .env file --
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=some
DB_USERNAME=root
DB_PASSWORD=
My MySQL port is 3306, Apache port is 80 (I changed it).
I don't change the password of PhpMyAdmin. But I get an error like this.
So I tried entering some password, then it is giving me same error with password using: YES
How can I fix it?
If you are using MAMP try this.
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=some
DB_USERNAME=root
DB_PASSWORD=root
Open your MAMP
There your will see 3 options
1. Preferences
2. Open WebStart Page
3. Start / Stop Servers
Click second one [ Open WebStart Page]. It will open mamp info page. Under MySQL area you can see your database connection details.
Hope it will help you.

PDOException SQLSTATE[28000] [1045] Access denied for user 'homestead'#'localhost'

I am new in Laravel 5.2.
I am getting following error:
[PDOException]
SQLSTATE[28000] [1045] Access denied for user 'homestead'#'localhost' (usin
g password: YES)
While I execute following command:
php artisan migrate
I am running application using vagrant on windows PC.
Please let me know why I am getting above error.
You are getting above error because on your .env file. If you open that from your project base directory then you will following default configuration:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Just change above values according to your development environment. Try again, Hopefully that would resolve your issue.
You must set the database connection in .env file.

Categories