Can’t connect to local MySQL server through socket

While running symfony jobeet tutorial, i got following error

fwh@pc11-desktop:~/web/jobeet$ php symfony doctrine:build-sql
>> doctrine  generating sql for models

                                                                                                                                                                                 
  While exporting model class 'JobeetAffiliate' to SQL: PDO Connection Error: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)  
                                                                                                                                                                                 

fwh@pc11-desktop:~/web/jobeet$

This is fixed by editing config/databases.yaml

Find line

dsn: 'mysql:host=localhost;dbname=jobeet'

Replace with

dsn: 'mysql:host=localhost;dbname=jobeet;unix_socket=/var/run/mysqld/mysqld.sock'

Posted in PHP

  • Cyril

    thank you very much for this tip, it’s just saved me lots of time