Laravel using vagrant: php artisan migrate --seed giving errors [duplicate] - php

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

Related

What's wrong with query error in Laravel with XAMPP on Mac?

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

SQLSTATE[HY000] [2002] Connection refused LARAVEL [duplicate]

This question already has answers here:
Laravel SQLSTATE[HY000] [2002] Connection refused
(11 answers)
Closed 1 year ago.
I am trying to run php artisan migrate on a new database I just created. I was having many troubles with connecting to mariadb but I managed to fix it. Now whenever i try to connect to it, for some reason I can type no password or literally any password and i still connect to it. I don't know if that's normal. Anyway, i modified the .env file in my laravel project to
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=liberty_comerce
DB_USERNAME=root
DB_PASSWORD=
But i get the error SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = liberty_comerce and table_name = migrations and table_type = 'BASE TABLE'). If I change DB_HOST=127.0.0.1 to DB_HOST=localhost i get the error SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = liberty_comerce and table_name = migrations and table_type = 'BASE TABLE').
I tried running
php artisan config:clear
php artisan config:cache
php artisan cache:clear
every time i changed anything. I've been looking for answer online but nothing seems to work.
Connection refused comes when .env DB_PORT doesn't match with your local db port. so first check the port and
then clear cache commands:
php artisan config:clear
php artisan config:cache
php artisan cache:clear
and then do
php artisan migrate.
I had the same issue yet to get to the solution to it, I have tried couple of things like changing 127.0.0.1 to localhost, and:
php artisan config:clear
php artisan config:cache
php artisan cache:clear

Laravel 8 - SQLSTATE[HY000] [2002] No such file or directory

I'm trying to make a project using Laravel and Sail but I'm getting errors when I'm trying to migrate or do anything related to the project's database (for example, seeding).
More specifically, when using artisan sail migrate or anything related, I'm getting the following errors:
When DB_HOST=localhost in my .env file:
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = noway and table_name = migrations and table_type = 'BASE TABLE')
When DB_HOST=127.0.0.1 in my .env file:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = noway and table_name = migrations and table_type = 'BASE TABLE')
What I've tried:
changing the DB_HOST to localhost and 127.0.0.1 (most common answer online, no succes)
making sure SQL is running
clearing cache for sail artisan migrate
./vendor/bin/sail down --rmi all -v to remove all images and volumes
changing username and password and putting them between '' or ""
None of the above have been of succes.
did you run ./vendor/bin/sail up after creating and setting .env ? if not please execute ./vendor/bin/sail down --rmi all -v to remove all images and volumes and then just ran ./vendor/bin/sail up to recreate the images and volumes.
Also as per laravel docs https://laravel.com/docs/8.x/sail you can connect to db by setting env DB_HOST to mysql
T had the same problem with pretty much the same conditions:
-I started with a laravel project then moved it to sail
the way I solved this was by adding an entry DB_PORT=3306 in the .env file and changed DB_HOST=localhost to DB_HOST=mysql as described in laravel docs : https://laravel.com/docs/8.x/sail#mysql
don't forget to check the new credentials that sail uses by default

"Temporary failure in name resolution" when running migration on Homestead VM [duplicate]

This question already has answers here:
"No such file or directory" or "No such host is known" when running migrations
(8 answers)
Closed 2 years ago.
I started a new Laravel 8 Project, I installed a fresh update of vagrant machine "laravel/homestead" in my project. I can "vagrant up" and I can see the mysql database created during the start.
I did "mysql -uhomestead -psecret" on ssh connection and it connect correctly, I can see my database "homestead" that is empty. I can also connect on the database with MySQL Workbench on my host machine with the adress "192.168.10.10:3306" and same credentials.
Now here my .env file :
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
But here the error message when I try to migrate :
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations and table_type = 'BASE TABLE')
I also tried with 33060 port and I changed 127.0.0.1 by localhost...
It should work, and it worked on my previous project...
I tried to destroy the machine with vagrant destroy and vagrant up again
I tried to clean cache of laravel with php artisan cache:clear and config:clear etc
But always the same error !
What did I forget or misunderstand ?
Thx everyone !!
Try deleting the DB_HOST=mysql
I think that is causing the issue

SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from `users` where `email` = test#test.com limit 1) [duplicate]

This question already has answers here:
PDOException SQLSTATE[HY000] [2002] No such file or directory
(37 answers)
Closed 4 years ago.
I made a new installation of laravel, I have a mysql which turns on the vagrant, I made the connection in the .env file and in the file config / database.php
i do not understand why i get this error, my system is linux and i use vagrant to host my sql
Can you help me to understand the problem ?
laravel error message
environment file laravel
laravel config/database file
If you have installed laravel just now, You should do :
php artisan migrate
It will install the migration and will create tables for you. one of which is users table which is used for authentication.
if you have installed fresh laravel, than you should run php artisan make:auth and then run php artisan migrate this will populate table users in your connected database.
php artisan migrate must work! and you go to /register
More info here: https://laravel.com/docs/5.7/authentication#introduction

Categories