Laravel 6 database connection error. Access denied for user - php

Couldn't connect to the database with laravel 6.0
SQL user and password were working fine and running smoothly on other project but the same credentials are not working on laravel 6.
I have created another user and give it all permissions but still got the same error.
I had cleared all kind of laravel cache,
remove the bootstrap and storage cache but nothing happened.
Please help me to solve this problem.
OS version: ubuntu 18.04
Server: nginx
Database: mysql 5.7.28
PHP: 7.2

Sharp(#) character recognizes as comment in .env file.
So you should put your password in double quotes("")
like this:
DB_PASSWORD="xfs#sds"

Related

MySQL+Laravel: SQLSTATE[HY000] [1045] Access denied for user 'so'#'localhost' but connection data is OK and config cache is cleared

I need help here, because it's driving me crazy. I'm trying to connect to the remote production DB but I'm unable. I have read tons of posts about this that are focusing on the credentials and also running the following commands to clean config that are stored in Laravel cache:
php artisan cache:clear
php artisan config:cache
php artisan config:clear
Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
Any of these are working for me.
I have checked very well the credentials both in my .env file and my database.php. I'm able to connect to a local database by using the ip "127.0.0.1" but I'm unable with the production DB stored in Google Cloud. It's good to mention that my local IP is allowed to access that Database and I'm able to connect by using MySql Workbench.
Here is what I see when I perform "php artisan tinker" and then "DB::connection()->getPdo();" to check my connection from terminal:
The only thing that calls my attention is the message containing "so#localhost" when I'm not performing a connection to localhost but I don't know if that's related with the issue.
Any other suggestion? I have lost too much time trying to find out what could be happening.
EDIT 1: Laravel Framework 5.8.38
After two days fighting with this one, I readed tons of posts and a lot of unuseful solutions I have found my solution by looking at this video.
Basically, you must stop you XAMPP MySQL Server and open C:\xampp\mysql\bin\my.ini and edit by adding the following command "skip-grant-tables" after the [mysqld] attribute. The result in this file might look this way:
# The MySQL server
default-character-set=utf8mb4
[mysqld]
skip-grant-tables
socket="C:/xampp/mysql/mysql.sock"
...
After that, I ran "php artisan tinker" and DB::connection()->getPdo(); and everything was connected again, but it's good if you first clean your cache and config.

Laravel with SQLite doesn't keep Auth data

I have project in Laravel 6 with MySQL database and its working fine. My client wants to use SQLite instead of MySQL database.
So i converted my existing database from database.sql to database.sqlite using following online tool
Online database conversion done here : https://www.rebasedata.com/
https://www.rebasedata.com/convert-mysql-to-sqlite-online
After that i have configured database.sqlite into .env file and into config/database.php file.
Issue : I am not able to go beyond login page. Every time i try to login it redirects me back to login page.
Debug : I reviewed that if I remove Authentication function then i am able to access controller which comes after login.
If I do comment to this line $this->middleware('auth'); following function It starts working.
public function __construct()
{
// $this->middleware('auth');
}
Conclusion : I found that I am not getting any value for $user = Auth::user();
So I think that session is not getting generated and stored correctly with SQLite database
Notes :
I have exported existing database using phpmyadmin and removed all
unnecessary comments from database.sql file.
I converted database.sql file online using this tool
https://www.rebasedata.com/convert-mysql-to-sqlite-online
As per my investigation Auth is not getting generated and stored.
I am using default laravel Auth, I generated that using laravel terminal command.
This setup works fine if I configure project with MySql database.
SQLite database configure Path is correct. I found error of not proper path while configuring it and i solved that.
I have already tested using this commands. : php artisan cache:clear --- php artisan route:cache --- php artisan config:cache --- php artisan view:clear
Any help are appreciated. Thanks in advance.

Laravel 5.5 can't connect to database

I have a larvael and I want it to make it in production. I have a server hosting and database on infomaniak.com.
I have upload all my file and I get a SQL timeout error :
SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from
characters where checked = 1 order by RAND() limit 1)
I have an other Laravel website on infomaniak and don't have this problem. I have check my .env file, my /config/database file and try php artisan config:clear or php artisan cache:clear. I also try to dump DB:connection() and the connection information are right.
I can connect to my homestead database in local and work fine. But when I try to connect to the SAME database than my other website with the same .env file and still have the timeout error.
How can I fix this ? Are there a way to clear another cache ? Completly lost :/
EDIT :
If i try :
if(DB::connection()->getDatabaseName()) {
echo "Yes! successfully connected to the DB: " . DB::connection()->getDatabaseName();
}
The page return Yes! successfully connected to the DB: db_name
EDIT 2 :
I just see my hosting server is in PHP 5.6 but it say that's my website is in PHP 7. Really confusing but maybe this informations is important (have another laravel on this server and works like that)
Your problem is the php version, if you're using laravel 5.5 then your host must have php 7 installed.
See the oficial docs here

Fresh-installation laravel project can't access postgresql database but can do php migrate

I already asked a question about this 2 days ago, here are the links
Got "password authentication failed for user" but in pgAdmin 3 its working
But I still didn't get an answer to solve the problem.
So I tried to create a new laravel project, then edit the .env file, check if php artisan migrate can run.
After I run php artisan migrate it's running, so it means that my credentials to PostgreSQL database are correct right? if not it will tell you password authentication failed for user "postgres", but I don't get any error at all, so I go to the next step. Now after I make sure everything is OK i run php artisan make:auth, it's a success without error at all, so I go to the web browser then run the site, I clicked the register / login button, fill the fields, submit then, it's happened again the nightmare
I got this message from the website
SQLSTATE[08006] [7] FATAL: password authentication failed for user "postgres" FATAL: password authentication failed for user "postgres" (SQL: select count(*) as aggregate from "users" where "email" = test#test.com)
Even though php artisan migrate run really well, so I've no idea why it's happening. Is there somebody that ever run into this problem before? or maybe why it's happening?
I already search all keywords that possible to fix this problem, but I can't found the answer, it's really stressed me out.
for the info I'm using:
PostgreSQL 9.6.8
Laravel 5.6
Ubuntu 17.10
Edited: Here is my pg_hba.conf
Check your database.php file in config directory, and check the pgsql array. If accessing DB credential values from .env not worked there, test it by directly putting credentials there. hope it will help. Artisan commands work by accessing the credentials from .env files directly,not from database.php that's why migration worked.
I had a similar problem, my generated password contained the character: '#'. This made it a comment line, ignoring the rest of the password. I just changed my password.

Laravel 5.1 migrate database to hosted mysql

How would I go about doing this (the title is the question), I've changed all my ENV files to my hosted mysql details. When i run php artisan migrate from composer I get the
"denied username#localhost using password yes error".
I've changed the port and everything but I'm not sure what to do anymore and I'm 99% sure that the details are correct I've tried them multiple times
You need check somethings:
are credentials valid (username, password and host)?
the database host is accessible by your application server?
.env file is correctly configured or have some config hard coded in app/config/database.php?
To validade connection, you can try this: http://www.w3schools.com/php/php_mysql_connect.asp
About configuration and enviroments : https://laravel.com/docs/5.2/configuration

Categories