-2

I get the following error when running php artisan migrate:

exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' in /opt/lampp/htdocs/larproject/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:47

What can I do to fix this?

Dov Benyomin Sohacheski
  • 7,133
  • 7
  • 38
  • 64

3 Answers3

1

Restart your mysql server

service mysqld restart
Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78
0

First message ... Can't connect to local MySQL ...

  1. So, check if database running.
  2. Check if you configured your connection.
  3. Check if you can access database with configured data.
  4. Be sure that you got user in database and he got proper privilages.
  5. Try to not use root user to connect with database, better solution, create new user workinkg only on 127.0.0.1 with strong password, and use him to communicate
szapio
  • 998
  • 1
  • 9
  • 15
0

Yours best bet is to check for the socket file.

  1. In your my.cnf
  2. Look for file permissions in /var/lib/mysql/mysql.sock (the php/apache user can access it?)

Fiddle you application running permissions and/or database configuration.

Thiago Macedo
  • 6,187
  • 1
  • 21
  • 22