I'm trying to setup already made project but I'm stuck at the migrating the DB. I'm using Laravel (5.6.34) on PHP 7.2.9, and MySQL (8.0.12). If I try to run php artisan migrate command I'm getting no output, command stays "active" but nothing happens, no errors.
I tried making fresh project, adding migration and running the same command, same thing. I noticed that all other (or at least bunch of them I tried) artisan commands are working but only migrate one doesn't.
.env info is correct and mysql is up and running.
Any help is appreciated.
Thank you!
Try the following;
1. Check your migration files for content.
2. Flush config with php artisan config:clear
3. Check if database is connected using tinker. Run php artisan tinker then paste in this code; DB::connection()->getPdo();
4. If PDO object is returned, your app is connected to the database. If not and PDOException with message 'SQLSTATE[HY000] [2002] Connection refused' is returned then mysql is not running. If database does not exist, you get the error PDOException with message 'SQLSTATE[HY000] [1049] Unknown database [your_db].
Assigning the password to DB User solved this issue for me (be sure populate DB_PASSWORD inside .env)
mysqladmin -u YOURDBUSER password 'newpassword'
Related
Now this is a really weird one.
My .env file is fine. When I run
php artisan config:clear
everything works. But when I run
php artisan config:cache
my database connection stops working:
SQLSTATE[HY000] [1045] Access denied for user 'foobar'#'xxx.xxx.xxx.xxx'
So again: My settings are correct. But when they are cached, they stop working. How could this possibly be?! Laravel seems to use some kind of old settings when using the cache, but I have no idea where these are coming from?
What I already tried:
php artisan optimize:clear
rm -rf bootstrap/cache/*.php
I ran into this issue while trying to setup a Laravel forge deployment script for zero downtime.
I hard coded the path to the ssl files for my database connection in /config/database.php. Changed that to use the values of .env, now it's working.
I have the problem with database connection after i ran a migration which is Illuminate\Database\QueryException. I've tried to ran the "php artisan migrate:fresh" command, but it didn't work. What should I do? Thanks in advance.
Here is the image
Check your php path in environment variables, php path must be of XAMP i.e "C:\xampp\php". Set this and then try to migrate again
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.
Prerequisites
In my local environment I am working with multiple tenants and Redis (Auth required).
To serve the project I am using Valet.
For this case I am addressing these two connections:
- basic_foo (is defined in my .env)
- tenant_foo (is the one to change to during a request)
Until now I successfully changed the connections like so:
config()->set('database.connections.mysql',
array_merge(
config()->get('database.connections.mysql') ,
['database' => 'tenant_foo']
);
Problem
However, now I am seeing an issue with the query builder, keeping or falling back to the basic connection.
I get the expected connection results of tenant_foo (same for Redis) when I run
dd(config()->get('database.connections.mysql'));
I get the wrong but apparently active results of basic_foo when I run
dd(\DB::connection()); // returns Illuminate\Database\MySqlConnection
So all in all the app will return this Illuminate\Database\QueryException
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'basic_foo.table_bar' doesn't exist...
where it should search for
'tenant_foo.table_bar'
Things that did not solve the problem yet
restarting Redis
reinstalling Redis
php artisan config:cache
php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan optimize
composer dump-autoload
Simply changing the database name to tenant_foo like below is not enough, as the config array remains the same of basic_foo.
\DB::connection()->setDatabaseName('tenant_foo');
Thoughts
I want to change the config-array the of \DB::connection(), but I don't know another way than the config->set().
I installed Telescope could this affect the db connection?
Any other ideas?
To dynamically change database name you should use:
DB::disconnect();
Config::set('database.mysql.database', 'tenant_foo');
DB::reconnect();
This worked for me:
\DB::disconnect('mysql');
Config::set('database.connections.mysql.database', 'tenant_foo');
\DB::reconnect('mysql');
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.