Laravel

SQLSTATE[HY000] [2002] Can’t connect to local MySQL server through socket Laravel

SQLSTATE[HY000] [2002] Can’t connect to local MySQL server socket – Laravel

I am using Laravel5.2 Homestead with vagrant and virtualbox.

connect to local MySQL

When I run php artisan migrate I got the following Error SQLSTATE[HY000] [2002] Can’t connect to local MySQL server through socket ‘/Applications/MAMP/tmp/mysql/mysql.sock’ (2). Because of this error I have struggled long time, After many research the following
solution solved my problem.

Inside my App directory I have run the following Command

It will destroy the current vagrant setup and will installed it newly.

After you enter the above command :

Are you sure you want to destroy the ‘default’ VM? [y/N] :  y // Enter y -> It will instralled the vagrant set up

It will execute the following lines

Once you reinstalled the vagrant



Go inside the vagrant box by entering below command :

Example :

broadband:firstApp marimuthu-mac$ vagrant ssh
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.19.0-25-generic x86_64)

* Documentation: https://help.ubuntu.com/
vagrant@firstapp:~$ cd /vagrant

It will take you to the vagrant box.

Now run you migration command

Example :

vagrant@firstapp:/vagrant$ php artisan migrate
Migration table created successfully.
Migrated: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_100000_create_password_resets_table

It will migrate your tables successfully.

Hope this will help someone.
If you like this article please don’t forget to share and comment.
Thanks!.
Happy coding…