psql SQL STATE[08006] Password Authentication Failed for User. Laravel - laravel

This is my first time working with Laravel, and I have a project set up, but I cannot connect to the database I created in Postgres. Whenever I try to connect to the database for a query (or anything), I get this error:
PDOException
SQLSTATE[08006] [7] FATAL: password authentication failed for user "marlie" FATAL: password authentication failed for user "marlie"
I'm using Windows 10, PostgreSQL 11, Laravel 6.0.4. I can connect to the database through pgAdmin4, command line, and psycopg2 without any password authentication issues. Only Laravel is giving me a hard time.
I've tried creating a new Laravel project, creating a new superuser (which I've tested, can successfully access the database from the other programs I mentioned above). I've also tried putting the username and password in both single and double quotes. I tried changing the database name to the OID number value in my postgreSQL file for the database. I've also tried adding the absolute file directory. I've tried changing port from 5432 to 54320. I've also tried other passwords.
Some search results suggested I play with the pg_hba.conf file and adding some lines such as (the indentation here is a little funny, but in the actual file it's all lined up):
local all marlie md5
local all marlie trust
host all all ::1/0 trust
host all all all trust
I've also tried changing everything to trust, in which case I can log in from command line without a password, but Laravel still won't let me! Also, my Windows laptop doesn't seem to support local connections since they're Unix-socket domains, so any local entries in pg_hba.conf end with the file not being able to load at all. Currently, my pg_hba.conf file is back to the default settings.
I've tried logging in by ssh into my Laravel project through Homestead.
$ vagrant ssh
$ psql -d natureFun -U marlie -W
Password:
psql: FATAL: Peer authentication failed for user "marlie"
I thought this was interesting because nowhere in my conf file do I say to use peer authentication. I've only ever tried trust and md5.
This is my .env file from Laravel
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=natureFun
DB_USERNAME=marlie
DB_PASSWORD=secret
This is pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all 127.0.0.1/32 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5

It seems that your first pg_hba.conf has a typo:
host all all all trust
Should be:
host all all <ip_address>/<netmask> trust
If it's a dev machine and you don't care about security (for now), just try:
host all all 0.0.0.0/0 trust
Also, unless you're acutally using IPv6, I'd recommend getting rid of the entire line containing ::1/0
Your second pg_hba.conf that you pasted should work, given that you restarted/reloaded the postmaster process -- you can usually do that through pg_ctl reload from the terminal or SELECT pg_reload_conf() from psql
Disclosure: I am an EnterpriseDB (EDB) employee

SOLVED! I misunderstood how Homestead worked (and also failed to mention that I am using it, sorry!)
when I put localhost or 127.0.0.1 in my .env file in my Laravel project, it references the Homestead Virtual as the localhost, NOT my actual computer.
Changing DB_HOST to my computer's IP address solved the problem and I am now happily connected.

Related

heroku pg:psql --app error CLI FATAL: no pg_hba.conf entry for host "hostIp", user "user name", database "Name", SSL off

I added the data base PostgreSQL on my Heroku app, I am trying to connect through CLI and pgadmin I getting the same error as below:
FATAL: no pg_hba.conf entry for host "hostIp", user "user name", database "Name", SSL off
I tried adding pg_hba.conf below entries:
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all all md5
# IPv6 local connections:
host all all ::1/128 md5
host all all all md5
still no luck, Hope anyone can assist me in that.
For this answer, I made an assumption that you are on Windows.
I ran into this problem as well and soon found out that I missed an important step which is to add the binaries of the PostgreSQL to the PATH environment variable.
This is where I found out:
Remember to update your PATH environment variable to add the bin directory of your Postgres installation. The directory will be similar to this: C:\Program Files\PostgreSQL<VERSION>\bin. If you forget to update your PATH, commands like heroku pg:psql won’t work.

How to use psql as postgres (asks for password, but I don't have one)?

I have installed Postgres using HomeBrew and I try to create a new user in it.
I try to use psql to create a new user and database in Postgres, so first I try to open up it by using sudo -u postgres psql, but it prompts me for a password. As far as I know there should be no password for this user by default.
I also tried to edit my pg_hba.conf, but this also seems fine for me:
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
Why does it keep prompting me a password (if there is a password what should be it)? If I simply try to run psql to log in using my current system user instead of postgres, and then provide my current user's password, that doesn't work either (I am on macOS by the way).

PostgreSQL: Windows creating new instance but can't login using pgAdmin3

I created new instance for postgesql, but cant login using pgAdmin3
I am using Windows 7 and PostgreSQL 9.5
Here's what i did:
Extract postgresql-9.5.0-1-windows-x64-binaries in D drive
Open cmd (admin account)
create data folder
Use initdb command
use pg_ctl command to logfile start and stop
use pg_ctl register command to register service
edit postgresql.conf
change port from 5432 to 5433
listen_addresses = localhost
listen_addresses = *
edit pg_hba.conf
Add IPv4 local connections
host all all samenet md5
Start the service
Lastly, add Network and local service with full control in Data folder where the new instance created.
------ I did not encounter any problems during this process.
But when I login using pgAdmin3 with postgres account or even admin account, same error occurs.
I don't know what I've missed.
Try changing the authentication method to trust. So you will be able to login without the password.
Add IPv4 local connections
host all all 127.0.0.1/32 trust
In my case I'm allowing all the localhost users to login without password.
If you use md5 client will need a password for authentication, if you use trust client can login without password.

Configuring Homestead to work with MySQL Workbench

I just started using Homestead today and so far I don't think I know what I am doing, previously I was using the inbuilt PHP server that comes with Laravel and I had MySQL server and workbench installed separately on my computer.
With this setup I was able to connect to my database with ease, however since I got my Homestead running I can't seem to access that database again. This error keeps popping up:
3/3 ErrorException in Connector.php line 47: SQLSTATE[HY000] [1045]
Access denied for user 'myproject_db101'#'localhost' (using password: YES)
(View: /home/vagrant/Projects/myproject/resources/views/layout/index.blade.php)
(View: /home/vagrant/Projects/myproject/resources/views/layout/index.blade.php)
How can I fix this?
I was facing the same issue and I tried below steps to fix it. Please let me know if they work for you.
Note the homestead ip address for your vagrant box. It is available in Homestead.yaml file under ~/.homestead directory. This directory location would be different on different OS. But since you have already installed vagrant with homestead you should know its location. For me the ip address was 192.168.10.10.
Open up the Mysql Connection wizard and provide the below settings
hostname = 192.168.10.10
port = 3306
username = homestead
password = secret
Test Your connection
For me these settings worked. Check if they work for you.
These other answers might have worked for you guys, but in case anyone has a case like mine, I'm just going to provide what worked for me. Hopefully it helps someone out. I'm working on a brand new homestead installation as of today, but on a very old mac in case thats relevant.
What worked for me was using the regular localhost ip of my machine as the host, and then the homested/secret combination for the password, and using the default port but with a 0 at the end.
This adds up to be the following settings:
Connection method: Standard (TCP/IP)
Host: 127.0.0.1
Username: homestead
Password: secret
Port: 33060
Hopefully this helps someone out. Its the only configuration that worked for me.
Try using homestead's default MySQL credentials: User: root Password: secret
If you are accessing the database from your computer via MySQL Workbench (not from within the homestead VM), you can use localhost:33060 (note: non-standard port). This is mapped to port 3306 within your VM.
From your application and any time you're working from within the homestead VM, you can connect to the database normally as localhost on port 3306.
Very likely a configuration issue. Either the user 'myproject_db101'#'localhost' has no password set or is not allowed to connect from localhost. You need another user with proper rights (e.g. the root user) to fix permissions for that user.

Unable to access the database of homestead environment (laravel) through MYSQL workbench

Unable to access the homestead database through MYSQL workbench Please help me out to solve this issue
error messages at time of testing the connection - "Failed to Connect to MySQL at 127.0.0.1:33060 with user homestead Lost connection to MySQL server at 'reading initial communication packet', system error: 0"
please take a note that
Bind address in my.cnf file is 127.0.0.1 (my.cnf file located at /etc/mysql/)
hosts file contains: 127.0.0.1 localhost projectname (which is located at /etc/)
I have tried changing bind address to 0.0.0.0 but it was also not worked.
Actually I was keep trying to setup the database connectivity by just considering the homestead environment ... But on Keep searching I found one link http://www.acnenomor.com/171821p1/laravel-homestead-vagrant-box-database-problems from where I got idea and I tried once again with the data shown in attached image and it worked for me ... so I am sharing this answer in general .. it may help someone...
Please take a note that I have also tried to connect the database of Laravel homestead environment by installing all the stuffs in other system too and it was worked fine as described in the official document.. so in my case it might be the problem of some changes in configuration file of mysql or any other related environment... so please first go through the official document... http://laravel.com/docs/4.2/homestead#daily-usage
The first thing you need to do is
vagrant up
and then use these connections below for a default homestead installation.
Connection Method: Standard (TCP/IP)
Hostname: 127.0.0.1
Port: 33060
Username: homestead
Password: secret
Try the alternate IP of 192.168.10.10
hostname = 192.168.10.10
port = 3306
username = homestead
password = secret
This works for me on Windows 10 Home Version 20H2 OS Build 19042.1165 (To find this information navigate to Start, Type 'About' and click 'About your PC').
ran into a similar problem while trying to use SQLyog on my windows machine to connect to mySQL on a Homestead environment. I was able to resolve this issue by adding
skip-name-resolve
to the VMs /etc/mysql/my.conf file.
Apparently (according the mysql error logs) connections from the local machine were coming from '10.0.2.2', which caused the warning "IP Address '10.0.0.2' could not be resolved".
You will need to re-add this line every time you spin up the environment.

Resources