Symfony 2: [PDOException] SQLSTATE[HY000] [2002] Connection refused entity generator

Giesburts picture Giesburts · Oct 30, 2015 · Viewed 7.4k times · Source

Recently I started working with Symfony. I created a project with the terminal/composer under the name "symfony" and also created a database on phpmyadmin (MAMP) which I called "symfony". I installed the project, and except a error of my timezone, my project was succesfully created and was running at my localhost.

After that I created a bundle called "SymfonyCinemaBundle" and my bundle was generated succesfully. I also tried to generate a entity but that is not working for me, and also the problem. After I open up the generator with the command, It asks for a shortcut name and I tried to use "SymfonyCinemaBundle:Movie" but that isn't working and gives me the following error:

*The Entity shortcut name: SymfonyCinemaBundle:Movie

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


  [Doctrine\DBAL\Driver\PDOException]        
  SQLSTATE[HY000] [2002] Connection refused  


  [PDOException]                             
  SQLSTATE[HY000] [2002] Connection refused  

doctrine:generate:entity [--entity ENTITY] [--fields FIELDS] [--format FORMAT] [--with-repository]*

I checked my parameters.yml but thats seems to be right. I've looked on the internet but nothing seems to help unfortunately. Does anyone has a solution for me?

Note: I'm using MAMP. The difference between normal and developers mode has no difference.

Answer

Giesburts picture Giesburts · Oct 30, 2015

Solved:

I've changed the host in parameters.yml to localhost instead of 127.0.0.1. I also added the right port number (normally it doesn't matter) and that solves the problem but has given me another error instead: "No such file or directy". It had to do with my mysql.sock so I used the following commands in my terminal:

sudo mkdir /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
sudo chown _mysql /var/mysql/mysql.sock
sudo chmod 777 /var/mysql/mysql.sock