1

I am newbie in laravel and trying to run php artisan migrate:install and got an error

[PDOException]                                                                                               
  SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' 

I have modified app/config/local/database.php and app/config/database.php like -

'fetch' => PDO::FETCH_CLASS,
        'default' => 'mysql',
    'connections' => array(

        'mysql' => array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'laravel_db',
            'username'  => 'root',
            'password'  => '',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        )
iNikkz
  • 3,729
  • 5
  • 29
  • 59
  • 2
    [possibly related question](http://stackoverflow.com/questions/5376427/cant-connect-to-local-mysql-server-through-socket-var-mysql-mysql-sock-38) – Supericy Dec 28 '14 at 10:20
  • @Supericy : But actual problem is not that. I have got the solution. Posted in my answer. – iNikkz Dec 28 '14 at 11:09

2 Answers2

2

Got the solution.

Actual problem was that we have to configure path in both the files : /etc/mysql/my.cnf and /opt/lampp/etc/my.cnf

socket      = /var/run/mysqld/mysqld.sock
iNikkz
  • 3,729
  • 5
  • 29
  • 59
1

Open database.php in config folder if you are using laravel 4+ version and in mysql credentials change localhost to 127.0.0.1.

and if you are using laravel 5+ version then edit env file and change localhost to 127.0.0.1

that's how I solved this problem on my ubuntu (development machine).

Hope it will help.