0

Just made a new laravel project and tried to migrate the tables and i got this :

SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = sugarDaddy and table_name = migrations and table_type = 'BASE TABLE')

I tried clearing the cache, the routes, the config, and changing the DBHOST from 127.0.0.1 to localhost and back as i saw in a few articles on so, but nothing worked. i'll leave here the migration and an ss to the database.

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sugarDaddy
DB_USERNAME=root
DB_PASSWORD=

the database ss

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Dan Alexandru
  • 91
  • 1
  • 7
  • What output gives you running `php artisan migrate:fresh`? The one in the question or other? Also, I'd try replacing `sugarDaddy` with `sugardaddy` or `sugar_daddy` to be sure that casing is not the issue. – Adrian Kokot Oct 26 '21 at 07:56
  • php artisan migrate:fresh shows: SQLSTATE[HY000] [2002] Connection refused (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE') – Dan Alexandru Oct 26 '21 at 07:59
  • Try changing `DB_HOST` to `localhost` and try again – Adrian Kokot Oct 26 '21 at 08:01
  • still the same: SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = sugardaddy and table_name = migrations and table_type = 'BASE TABLE') – Dan Alexandru Oct 26 '21 at 08:02
  • And are you sure that when you had `DB_HOST=127.0.0.1` you passed the correct connection data? I mean the username, password? – Adrian Kokot Oct 26 '21 at 08:04
  • DB_USERNAME=root DB_PASSWORD= didnt even changed those as i said i just created the project with composer create-project laravel/laravel SDApp and tried to migrate the tables and i just got that error , it's the first time when i see it, cuz ususally it worked fine – Dan Alexandru Oct 26 '21 at 08:07
  • Yes, but those username and password must match the user in your local database system. So if you are using MySQL server you probably had to set some password, just pass it to the `.env` file. – Adrian Kokot Oct 26 '21 at 08:08
  • nope i just opened the mamp server as i usually do and everything worked without needing me to pass something – Dan Alexandru Oct 26 '21 at 08:09

2 Answers2

4

On your mac, in your .env file, add the line below and remember to thank me later

DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock 
MUHINDO
  • 788
  • 6
  • 10
3

I can see from the screenshot that your phpMyAdmin is connecting to the database at 8889 port, your env has DB_PORT=3306, change to DB_PORT=8889.

Summary of the comment section:

Dan is using MAMP, so the config for mysql connection should contain (for default MAMP settings):

DB_HOST=localhost
DB_PORT=8889
DB_USERNAME=root
DB_PASSWORD=root
Adrian Kokot
  • 2,172
  • 2
  • 5
  • 18
  • now i got this: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE') – Dan Alexandru Oct 26 '21 at 08:14
  • And that's clear error that you have some password for the database but you haven't passed it to the config. You probably had to type login and password while connecting to the phpMyAdmin. Pass the same login and password to the laravel `.env` file as `DB_USERNAME` and `DB_PASSWORD`. – Adrian Kokot Oct 26 '21 at 08:15
  • but i didnt set one – Dan Alexandru Oct 26 '21 at 08:45
  • i didnt have to login into phpmyadming just wrote the link and enter without login or something else – Dan Alexandru Oct 26 '21 at 08:46
  • 1
    You wrote that you are using MAMP, after quick google I've found [that](https://ar.al/760/). Try `DB_USERNAME=root` and `DB_PASSWORD=root`. – Adrian Kokot Oct 26 '21 at 08:48