Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony3 - SQLSTATE[HY000] [2002] No such file or directory

Tags:

php

mysql

symfony

I am new to Symfony and started doing some tutorials in order to get some things done. I am working on a Linux Mint 18 machine and a standard Symfony3-project.

I'd like to create a simple database to play around with it, but I am encountering an error I can't find the right solution for.

My parameters.yml file looks like this:

parameters:
   database_host: localhost
   database_port: null
   database_name: symfony
   database_user: root
   database_password: null
   mailer_transport: smtp
   mailer_host: 127.0.0.1
   mailer_user: null
   mailer_password: null
   secret: (not relevant)

My Genus.php file looks like this:

namespace AppBundle\Genus;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="genus")
 */
class Genus
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer")
     */
    private $id;
    /**
     * @ORM\Column(type="string")
     */
    private $name;

}

When I execute the command dpkg -l php*mysql I get the following result:

dpkg -l php*mysql
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name              Version       Architecture  Description
+++-=================-=============-=============-============================
un  php-pdo-mysql     <none>        <none>        (no description available)
ii  php7.0-mysql      7.0.8-0ubuntu amd64         MySQL module for PHP
un  php7.0-pdo-mysql  <none>        <none>        (no description available)

When I try to create a local database using the command prompt using

XXX@XXX-pc ~/PhpstormProjects/test_symfony $ php bin/console doctrine:database:create

This is what I get:

[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory
[Doctrine\DBAL\Driver\PDOException] SQLSTATE[HY000] [2002] No such file or directory
[PDOException] SQLSTATE[HY000] [2002] No such file or directory

I've came across many other topics but wasn't able to find the right answer. Could anyone tell me what I am missing here? Any help is much appreciated :)

like image 469
M. Douglas Avatar asked Oct 08 '16 17:10

M. Douglas


1 Answers

In my case, I only changed localhost->127.0.0.1 and it worked!

like image 150
Mari Y Avatar answered Oct 02 '22 12:10

Mari Y