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


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: 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 <strong>dpkg -l php*mysql</strong> 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]<br /> An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory<br /> [Doctrine\DBAL\Driver\PDOException] SQLSTATE[HY000] [2002] No such file or directory<br /> [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 :)


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


Had the same error.

OS: macOS High Sierra. MAMP 5.0.1

The problem was that the default MySQL port on MAMP was <strong>8889</strong> and in parameters.yml it was <strong>3306</strong>


May be It's too late but I had the same issue "SQLSTATE[HY000] [2002] No such file or directory" on my symfony 3.2.9 deployment

I fixed it by changing the database_host value from "localhost" to my server IP on my parameters.yml file

but I had this another error message when trying to run commandline by SSH:

[Doctrine\DBAL\Exception\ConnectionException] An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused

I finaly fix it by adding these 2 lines on my config.yml file in Doctrine configuration section :

unix_socket: /var/lib/mysql/mysql.sock server_version: '5.5'

all my final doctrine configuration is like this:

doctrine: dbal: driver: pdo_mysql host: '%database_host%' port: '%database_port%' dbname: '%database_name%' user: '%database_user%' password: '%database_password%' unix_socket: /var/lib/mysql/mysql.sock server_version: '5.5' charset: UTF8

hopefully this helps someone



[PDOException] SQLSTATE[HY000] [2002] No such file or directory


This error occurs generally when your web application is not connected to the database. As per your <strong>parameter.yml</strong> it's searching for mysql server & wasn't getting connected because at that time <strong>mysql</strong> wasn't installed there at your machine.


My knowledge of MySQL suggests one variant which might happen and explain this:

You had (old) mysqld running, then deleted out all files from datadir. Then probably new server wasn't able to start up Then you connected to that old mysqld, which is still running, but getting 'No such file or directory' error trying to access own system files (which were deleted).


if you use mamp test this:

sudo ln -s /Applications/MAMP/tmp/mysql /var/mysql


  • js script works only when alert is present - not an ajax call
  • What is the better way of publishing global constants in Java?
  • Changewheel functionality How it works?
  • Java regex to remove SQL comments from a string
  • jQuery datepicker displaying a Buddhist date
  • What means “The app must be signed with a development identity” ?
  • How to add external data file into developing R package?
  • Java regex to remove SQL comments from a string
  • jquery datepicker onselect not working
  • Chrome extension file upload browse window position off screen
  • POSTGRESQL - ERROR: could not load library pgafis.so : undefined symbol: lfsparms_V2
  • llvm::DIInstruction getFilename returns filename with a directory, I just want the filename
  • C++ NetBeans Run-Configuration passing arguments-issue
  • Is it possible to get Maven dependencies in a property at run-time?
  • Android google maps v2 execute asynctask when user stops moving the camera
  • How to silence gem errors after switching to bundler
  • Parsing XML file in Perl - Retain sequence
  • Can't remove inline event handler in chrome
  • Use function defined in one cpp file in function defined in another cpp file in Rcpp
  • Parsing Complex JSON file with JQ Issue
  • Version in docker-compose is unsupported
  • how to bypass pinentry (passphrase screen) while decrypting a file using gpgme
  • HALF_PTR Windows data type
  • Boost binary serialization doesn't work occasionally. The parsed data is corrupted sometimes
  • Can XOR be expressed using SKI combinators?
  • Appium MobileElement swipe returns unknown server error
  • F#: In which memory area is the continuation stored: stack or heap?
  • Most efficient way to move table rows from one table to another
  • Building Qt project for C++11 standard
  • Compiling dlib on OS X
  • python script hangs on input method when running spark
  • How to generate and display a QR Code in ionic 2
  • How to use JavaScript to determine whether a file exists in a directory?
  • With Hadoop, can I create a tasktracker on a machine that isn't running a datanode?
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • Regex thinks I'm nesting, but I'm not
  • What is the “return” in scheme?
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • How to disable jQuery.jplayer autoplay?