skip to Main Content

I had a laravel 7 app I developed on my local (MAMP). I now want to set it up on my website hosting account (apache2, php7.4, mysql server). I did a git pull to pull down all the files and now when I do a

php artisan migrate

I get an error that says

 SQLSTATE[HY000] [2002] No such file or directory (SQL: create table `migrations` (`id` int unsigned not null auto_increment primary key, `migration` varchar(191) not null, `batch` int not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

I am able to login to the phpmyadmin on the hosting server and see my empty database there.
My env file looks like this:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=commandcenterdb
DB_USERNAME=****
DB_PASSWORD=******

and my config/database.php file looks like this

    'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE',' commandcenterdb'),
        'username' => env('DB_USERNAME', '*****'),
        'password' => env('DB_PASSWORD', '********'),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => false,
        'engine' => null,
        'options' => extension_loaded('pdo_mysql') ? array_filter([
            PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
        ]) : [],

2

Answers


  1. I got the same error when using MAMP on a mac

    SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = php-laravel and table_name = migrations)
    

    I solved it by adding DB_SOCKET on .env file

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=your-database-name
    DB_USERNAME=your-username
    DB_PASSWORD=your-password
    DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
    

    if it doesn’t work try to modify the charset and collation on config/database.php file

    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ]
    
    Login or Signup to reply.
  2. its also worth to cross check ,i had UNIX_SOCKET instead of DB_SOCKET in the .env

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search