I got a laravel app (9.19.0) and php (8.1.1) linked to a mariadb database.
Each part of the app is in a specific docker container.
When I try to do php artisan migrate to build my tables, I got the error
SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not respond properly after a certain amount of time or an established connection failed because the connecting host did not respond (SQL: select *
from information_schema.tables where table_schema = mydatabasename and table_name = migrations and table_type = 'BASE TABLE')
\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDO::__construct("mysql:host=172.19.0.3;port=3306;dbname=mydatabasename", "username", "password", [])
The point is when I run an API request on the same application, I can access my database with the exact same .env file.
I tried to :
php artisan cache:clear : Clear cache but no changes
Reinstall completely my docker containers (volumes & containers) : No changes
Change the DB_HOST parameter from IP to container name : No changes
Create manually the table migrations : No changes
For me, the probleme come from the request returned in the error message, because when I type the exact same query select * from information_schema.tables where table_schema = mydatabasename and table_name = migrations and table_type = 'BASE TABLE' I got an error saying that mysql cannot found the field mydatabasename but when I put the parameters between quotes no more errors select * from information_schema.tables where table_schema = 'mydatabasename' and table_name = 'migrations' and table_type = 'BASE TABLE'
For me, this is pure magic, why can't artisan connect to my database but my app can since they are using the same .env file and (I guess) the same underlaying method to connect to the database ?
Note : With the exact same setup, things seems to work previously
Related
SQLSTATE[HY000] [1049] Unknown database 'laravel' (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
found this somewhere and it was helpful
The DB_USERNAME should be set to root if you do not have a default username
If no password is set on the database, clear it DB_PASSWORD
After completion of .env edit must be clear cache: php artisan config:cache
After Run the migrate Artisan command: php artisan migrate
I am a beginner programmer and use Laravel with XAMPP on Mac. And all my attempts to create migrations lead to Query Error:
Illuminate\Database\QueryException
SQLSTATE[HY000] [2006] MySQL server has gone away (SQL: select * from information_schema.tables where table_schema = laravel-app and table_name = migrations and table_type = 'BASE TABLE')
My PHP version is 7.3.29 on MacBook
In XAMPP web-server: Apache/2.4.48 (Unix) OpenSSL/1.1.1k PHP/8.0.10 mod_perl/2.0.11 Perl/v5.32.1
What steps should i take to customize the request?
This is not a Laravel issue, but a general MySQL Issue. Maybe the server is not running. Are you sure you're running MySQL in the background?
Check this link: MySQL Gone Away
Do the following checks in your system:
The Database Engine is running
You have created your database
You have created an user and granted permissions to the database
You have setup the user and the database in your Laravel's .env file.
After this, try to run the migrations command again, which is:
php artisan migrate
As explained Here
When i run the command php artisan migrate it gives me this error:
SQLSTATE[08006] [7] could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432? (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')
In as much as i am using a database.sqlite file for my database
My .env file:
DB_CONNECTION=sqlite
The problem was fixed by doing the following:
I added the path for my database file in my .env, then it looked like this below
DB_CONNECTION=sqlite
DB_DATABASE='database/database.sqlite'
Then I cleared my cache using php artisan config:cache
Then I ran php artisan migrate and it worked!
This question already has answers here:
MySQL connection not working: 2002 No such file or directory
(23 answers)
Mysql localhost != 127.0.0.1?
(4 answers)
Closed 2 years ago.
homestead version: 9.2.0
vagrant version: 2.2.7
php version: 7.2.21
mysql version: 8.0.18
I created a new laravel project. I created a database called tickets. I've added the third party code from https://github.com/creativetimofficial/material-dashboard-laravel. When I get to step where you run "php artisan migrate --seed" I'm getting two different errors depedning on how I set db port in .env file.
Here's a picture of my db users and their hosts.
when DB_HOST=127.0.0.1 and I run the artisan migrate I get an error saying Connection refused. I only tried using 127.0.0.1 because I saw online people saying to use this instead of localhost. Since the connection is refused I have a feeling this isn't correct.
When DB_HOST=localhost and I run artisan migrate I get an error saying
No such file or directory (SQL: select * from information_schema.tables where table_schema = tickets and table_name = migrations and table_type = 'BASE TABLE') {"exception":"[object] (Illuminate\\Database\\QueryException(code: 2002): SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = tickets and table_name = migrations and table_type = 'BASE TABLE') at /Applications/MAMP/htdocs/ticket-dashboard/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669)
Questions:
1) should I be using the IP instead of localhost and if so why do I get connection refused with using the IP?
2) If using localhost is fine, what needs to be fixed to bypass this error?
I've been testing everything I can find online to help, but this is the closest I've gotten. Any advice or ideas would be greatly appreciated
I want to connect Laravel with Postgresql database
when I run
php artisan migrate
I get this error
SQLSTATE[08006] [7] timeout expired (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations)
my .env
DB_CONNECTION=pgsql
DB_HOST=projects.cggts***.rds.amazonaws.com
DB_PORT=5432
DB_DATABASE=projects
DB_USERNAME=*********
DB_PASSWORD=*********
It'll probably inbound VPC problem on AWS . You have to update IP range for your RDS db. You'll find it under EC2->Network & Security->Security Groups . Have fun ;)