Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.6 | PHP artisan migrate not working

I've tried quite a few things that I've seen when googling this issue, but nothing has worked for me yet.

I'm running Mac OS 10.13.4 w/ MAMP. This command works on my Windows Machine with XAMPP.

Things I've tried:

  • Changing: `127.0.0.1` to `localhost` in `.env`
  • Changing: `DB_PORT` from `3306` to `8889` in `.env`
  • Adding: `'unix_socket' => '/tmp/mysql.sock'`, to `config\database.php`

Here's what's returned when entering php artisan migrate -v into terminal.

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

  at /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php: 664
  660:         // If an exception occurs when attempting to run a query, we'll format the error
  661:         // message to include the bindings with SQL, which will make this exception a
  662:         // lot more helpful to the developer instead of just the database's errors.
  663:         catch (Exception $e) {
  664:             throw new QueryException(
  665:                 $query, $this->prepareBindings($bindings), $e
  666:             );
  667:         }
  668: 
  669:         return $result;

  Exception trace:

  1   PDOException::("SQLSTATE[HY000] [2002] No such file or directory")
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php : 68

  2   PDO::__construct("mysql:unix_socket=/tmp/mysql.sock;dbname=b_rowland", "root", "", [])
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php : 68

  3   Illuminate\Database\Connectors\Connector::createPdoConnection("mysql:unix_socket=/tmp/mysql.sock;dbname=b_rowland", "root", "", [])
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php : 44

  4   Illuminate\Database\Connectors\Connector::createConnection("mysql:unix_socket=/tmp/mysql.sock;dbname=b_rowland", [])
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php : 24

  5   Illuminate\Database\Connectors\MySqlConnector::connect()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php : 183

  6   Illuminate\Database\Connectors\ConnectionFactory::Illuminate\Database\Connectors\{closure}()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 915

  7   call_user_func(Object(Closure))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 915

  8   Illuminate\Database\Connection::getPdo()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 940

  9   Illuminate\Database\Connection::getReadPdo()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 399

  10  Illuminate\Database\Connection::getPdoForSelect()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 325

  11  Illuminate\Database\Connection::Illuminate\Database\{closure}("select * from information_schema.tables where table_schema = ? and table_name = ?")
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 657

  12  Illuminate\Database\Connection::runQueryCallback("select * from information_schema.tables where table_schema = ? and table_name = ?", Object(Closure))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 624

  13  Illuminate\Database\Connection::run("select * from information_schema.tables where table_schema = ? and table_name = ?", Object(Closure))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 333

  14  Illuminate\Database\Connection::select("select * from information_schema.tables where table_schema = ? and table_name = ?")
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Schema/MySqlBuilder.php : 18

  15  Illuminate\Database\Schema\MySqlBuilder::hasTable("migrations")
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php : 169

  16  Illuminate\Database\Migrations\DatabaseMigrationRepository::repositoryExists()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php : 545

  17  Illuminate\Database\Migrations\Migrator::repositoryExists()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php : 97

  18  Illuminate\Database\Console\Migrations\MigrateCommand::prepareDatabase()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php : 63

  19  Illuminate\Database\Console\Migrations\MigrateCommand::handle()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php : 29

  20  call_user_func_array([])
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php : 29

  21  Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php : 87

  22  Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Object(Closure))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php : 31

  23  Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), [])
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Container/Container.php : 564

  24  Illuminate\Container\Container::call()
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Console/Command.php : 183

  25  Illuminate\Console\Command::execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/symfony/console/Command/Command.php : 252

  26  Symfony\Component\Console\Command\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Console/Command.php : 170

  27  Illuminate\Console\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/symfony/console/Application.php : 865

  28  Symfony\Component\Console\Application::doRunCommand(Object(Illuminate\Database\Console\Migrations\MigrateCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/symfony/console/Application.php : 241

  29  Symfony\Component\Console\Application::doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/symfony/console/Application.php : 143

  30  Symfony\Component\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Console/Application.php : 88

  31  Illuminate\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php : 122

  32  Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      /Users/blazerowland/Documents/Sites/Personal/Portfolio/artisan : 37
like image 637
Blaze Rowland Avatar asked Apr 14 '18 18:04

Blaze Rowland


2 Answers

In your .env file, regarding you DB configuration, do you have all settings filled in?

Here's the env vars:

DB_CONNECTION=
DB_HOST=
DB_PORT=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=

Also, if you are suing mysql sock, you will need the DB_SOCKET=< path >/mysql.sock

like image 118
Tiago Mateus Avatar answered Oct 25 '22 05:10

Tiago Mateus


Try using changing the environment.

 php artisan migrate --env=dev
like image 37
Maruf Alom Avatar answered Oct 25 '22 07:10

Maruf Alom