Solucionado (ver solução)
Solucionado
(ver solução)
9
respostas

conexão Laravel x Mysql

Alguem poderia me ajudar por gentileza? Não consigo conectar meu banco ao meu projeto. sempre da erro: 1/1 PDOException in Connector.php line 55: SQLSTATE[HY000] [2002] No such file or directory in Connector.php line 55 at PDO->construct('mysql:host=localhost;port=3306;dbname=estoque_laravel', 'root', '', array('0', '2', '0', false, '0')) in Connector.php line 55 at Connector->createConnection('mysql:host=localhost;port=3306;dbname=estoque_laravel', array('driver' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'database' => 'estoque_laravel', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, 'engine' => null, 'name' => 'mysql'), array('0', '2', '0', false, '0')) in MySqlConnector.php line 24 at MySqlConnector->connect(array('driver' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'database' => 'estoque_laravel', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, 'engine' => null, 'name' => 'mysql')) in ConnectionFactory.php line 61 at ConnectionFactory->Illuminate\Database\Connectors{closure}() at call_user_func(object(Closure)) in Connection.php line 924 at Connection->getPdo() in Connection.php line 792 at Connection->reconnectIfMissingConnection() in Connection.php line 677 at Connection->run('select from produtos', array(), object(Closure)) in Connection.php line 349 at Connection->select('select from produtos') at call_user_func_array(array(object(MySqlConnection), 'select'), array('select * from produtos')) in DatabaseManager.php line 317 at DatabaseManager->call('select', array('select from produtos')) in Facade.php line 217 at DatabaseManager->select('select from produtos') in Facade.php line 217 at Facade::__callStatic('select', array('select from produtos')) in ProdutoController.php line 9 at DB::select('select from produtos') in ProdutoController.php line 9 at ProdutoController->lista() at call_user_func_array(array(object(ProdutoController), 'lista'), array()) in Controller.php line 80 at Controller->callAction('lista', array()) in ControllerDispatcher.php line 146 at ControllerDispatcher->call(object(ProdutoController), object(Route), 'lista') in ControllerDispatcher.php line 94 at ControllerDispatcher->Illuminate\Routing{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52 at Pipeline->Illuminate\Routing{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96 at ControllerDispatcher->callWithinStack(object(ProdutoController), object(Route), object(Request), 'lista') in ControllerDispatcher.php line 54 at ControllerDispatcher->dispatch(object(Route), object(Request), 'estoque\Http\Controllers\ProdutoController', 'lista') in Route.php line 174 at Route->runController(object(Request)) in Route.php line 140 at Route->run(object(Request)) in Router.php line 724 at Router->Illuminate\Routing{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52 at Pipeline->Illuminate\Routing{closure}(object(Request)) in VerifyCsrfToken.php line 64 at VerifyCsrfToken->handle(object(Request), object(Closure)) at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 at Pipeline->Illuminate\Routing{closure}(object(Request)) in ShareErrorsFromSession.php line 49 at ShareErrorsFromSession->handle(object(Request), object(Closure)) at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 at Pipeline->Illuminate\Routing{closure}(object(Request)) in StartSession.php line 64 at StartSession->handle(object(Request), object(Closure)) at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 at Pipeline->Illuminate\Routing{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37 at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 at Pipeline->Illuminate\Routing{closure}(object(Request)) in EncryptCookies.php line 59 at EncryptCookies->handle(object(Request), object(Closure)) at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 at Pipeline->Illuminate\Routing{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 at Pipeline->then(object(Closure)) in Router.php line 726 at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699 at Router->dispatchToRoute(object(Request)) in Router.php line 675 at Router->dispatch(object(Request)) in Kernel.php line 246 at Kernel->Illuminate\Foundation\Http{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52 at Pipeline->Illuminate\Routing{closure}(object(Request)) in CheckForMaintenanceMode.php line 44 at CheckForMaintenanceMode->handle(object(Request), object(Closure)) at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 at Pipeline->Illuminate\Routing{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 at Pipeline->then(object(Closure)) in Kernel.php line 132 at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99 at Kernel->handle(object(Request)) in index.php line 54 at require_once('/Users/Flavio/Desktop/laravel/public/index.php') in server.php line 21

9 respostas

Oi Flavio, tudo bom?

Tenta trocar o host da sua conexão de:

localhost

para:

127.0.0.1

Esse problema pode ocorrer pois o localhost usa sockect UNIX que não encontra o database no diretorio padrão. Já o 127.0.0.1 usa TCP que evita esse tipo de conflito =)

Se o erro persistir, compartilha com a gente!

Abraço e bons estudos =)

Tvz resolva, mas agora não estou conseguindo testar pq esta dando outro erro, mas na hora de subir o servidor: Warning: require(/Users/Flavio/Documents/Projetos/ladonna/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /Users/Flavio/Documents/Projetos/ladonna/bootstrap/autoload.php on line 17

Fatal error: require(): Failed opening required '/Users/Flavio/Documents/Projetos/ladonna/bootstrap/../vendor/autoload.php' (include_path='.:') in /Users/Flavio/Documents/Projetos/ladonna/bootstrap/autoload.php on line 17

alguem sabe a solução por gentileza?

Tenta rodar um composer update:

composer update --no-scripts

Se você não instalou o composer:

composer install

=)

Mesma coisa... melhor começar tudo do zero? tentei reinstalar td de novo.... mas os erros persistem. devo ter feito algo errado.

Ola, por gentileza, preciso de ajuda, pois ainda não resolvi meu problema.

Configurando tanto pelo .env quanto pelo arquivo database, qndo coloco o host como "127.0.0.1", ele retorna somente a instrução em html:

Listagem de Produtos

;

Quando colo o host como "Localhost", ele retorna esse erro: Whoops, looks like something went wrong.

1/1 PDOException in Connector.php line 55: SQLSTATE[HY000] [2002] No such file or directory in Connector.php line 55 at PDO->__construct('mysql:host=localhost;port=3306;dbname=estoque_laravel', 'root', '', array('0', '2', '0', false, '0')) in Connector.php line 55 at Connector->createConnection('mysql:host=localhost;port=3306;dbname=estoque_laravel', array('driver' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'database' => 'estoque_laravel', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, 'engine' => null, 'name' => 'mysql'), array('0', '2', '0', false, '0')) in MySqlConnector.php line 24 at MySqlConnector->connect(array('driver' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'database' => 'estoque_laravel', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, 'engine' => null, 'name' => 'mysql')) in ConnectionFactory.php line 61

Segui todos passos da aula, mas não consigo passar dessa fase. O Mysql esta rodando com o dump importado, solicitado pelo curso; fiz os testes conforme a aula tbm e esta td ok.

Por gentileza, me ajudem a resolver esse problema. Obrigado.

Compartilha com a gente, se possivel, seu arquivo config/database.php?

Verifica também em qual porta seu mysql está rodando, pra isso você pode usar o comando:

mysql -u root -p // entra no mysql
SHOW GLOBAL VARIABLES LIKE 'PORT';

Aguardo retorno =)

Obrigado pelo retorno; A porta que esta sendo usada é a 3306;

Segue abaixo codigo do database e depois do .env. obrigado:

database.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | PDO Fetch Style
    |--------------------------------------------------------------------------
    |
    | By default, database results will be returned as instances of the PHP
    | stdClass object; however, you may desire to retrieve records in an
    | array format for simplicity. Here you can tweak the fetch style.
    |
    */

    'fetch' => PDO::FETCH_CLASS,

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */


    'default' => env('DB_CONNECTION', 'mysql'),

    /*
    'default' => 'mysql'),
    */
    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'estoque_laravel'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'public',
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer set of commands than a typical key-value systems
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => [

        'cluster' => false,

        'default' => [
            'host' => env('REDIS_HOST', 'localhost'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
        ],

    ],

];







.env

APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:6KRSWQiPgudknweUR0u8WUpoFdQlsuwR6QSot78JzA0=
APP_URL=http://localhost



CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

Aguardo retorno.

solução!

Tenta trocar aqui:

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),

De localhost, para 127.0.0.1:

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),

De resto, a configuração parece OK.

Qualquer problema, compartilha aqui com a gente =)

Deu certo, muito obrigado!!