Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Unrivaled's avatar

TablePlus error connecting to Laravel Sail `localhost` on Linux

Laravel's documentation for Sail says to use address localhost at port 3306 to connect to a default installation of Laravel Sail, but this spits out an error:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I ran netstat -an | grep 3306 which confirms that MySQL is indeed listening on port 3306 as expected.

The solution was to change localhost to either 0.0.0.0 or 127.0.0.1 (both worked). I have not tested/confirmed this error using the Docker development ecosystem on my other Mac or Windows development platforms yet, but I just wanted to put this out there in case anyone else bumps into this problem. Laravel's documentation might want to make mention of this in their Sail section.

Hope this helps somebody!

0 likes
1 reply
LaryAI's avatar
Level 58

It sounds like you're encountering an issue with connecting to the MySQL server when using Laravel Sail on a Linux environment. The error message indicates that the MySQL client is trying to connect via a Unix socket, which is not available in the Docker container setup used by Sail.

The solution you found—changing localhost to 127.0.0.1 or 0.0.0.0—is indeed correct. This is because localhost in many Linux distributions resolves to a Unix socket, whereas 127.0.0.1 and 0.0.0.0 resolve to TCP connections, which is what Docker containers use.

Here is a more detailed solution:

  1. Update your .env file: Change the DB_HOST value from localhost to 127.0.0.1 or 0.0.0.0.

    DB_HOST=127.0.0.1
    
  2. Restart Laravel Sail: After making changes to the .env file, you should restart the Sail environment to ensure the changes take effect.

    ./vendor/bin/sail down
    ./vendor/bin/sail up -d
    
  3. Configure TablePlus: When setting up your connection in TablePlus, use the following settings:

    • Host: 127.0.0.1 or 0.0.0.0
    • Port: 3306
    • User: sail
    • Password: password (or whatever you have set in your .env file)
    • Database: your_database_name

Here is a sample configuration for TablePlus:

Host: 127.0.0.1
Port: 3306
User: sail
Password: password
Database: your_database_name

By making these changes, you should be able to connect to your MySQL database running in the Laravel Sail Docker container without encountering the Unix socket error.

If you continue to experience issues, ensure that your Docker containers are running and that there are no firewall rules blocking the connection.

Hope this helps!

Please or to participate in this conversation.