Skip to content

MySQL error 2002: Can't connect to local MySQL server

The client could not reach the local endpoint it tried to use.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

A TCP connection can instead fail with:

ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (61)

The socket path, address, and system error number vary.

A Terminal client can use a Unix socket for local MySQL access. TableAI uses a TCP host and port. A socket failure and a failed TableAI connection can therefore need different fixes.

Check the likely causes first:

  • The MySQL service or container is stopped.
  • The TCP port or socket path is incorrect.
  • The container has no published port.
  • MySQL does not listen on the selected TCP address.
  • A network rule blocks a remote host.

Use the same host, port, and user as your saved connection. For a server on your Mac:

Terminal window
mysqladmin --protocol=TCP -h 127.0.0.1 -P 3306 -u demo_user -p ping

Enter the password at the prompt. An Access denied response establishes that MySQL answered, but the login still needs the 1045 checks.

  1. Start the MySQL service if it is stopped.
  2. Check the TCP port and bind-address in the server configuration.
  3. Compare those settings with Host and Port in TableAI.
  4. Repeat the TCP test.

For a socket-only Terminal error, compare the client’s socket path with the server configuration. Enter a TCP address in TableAI; see local MySQL setup.

Run docker ps and inspect the port mapping. Follow the Docker guide to map the published port to TableAI.

For a local Cloud SQL Auth Proxy, confirm that its TCP listener is running. Use the proxy’s local port as described in the Cloud SQL guide.

For a cloud server, confirm public access and the allowed client IP, or reconnect to the required private network. For an SSH route, follow SSH tunnel troubleshooting.

For a LAN host that times out, check macOS Local Network permission. Loopback connections to 127.0.0.1 do not need this permission.

For a company server, send the administrator the host, port, user, redacted error, and failure time. Never send the password.

TableAI labels codes 2002 and 2003 Connection Failed. Read the details to identify the address or connection stage that failed.

Use connection troubleshooting for further checks. Once connected, continue with write and run SQL, or return to the MySQL overview.