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.
What MySQL error 2002 means
Section titled “What MySQL error 2002 means”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.
Test the TableAI endpoint
Section titled “Test the TableAI endpoint”Use the same host, port, and user as your saved connection. For a server on your Mac:
mysqladmin --protocol=TCP -h 127.0.0.1 -P 3306 -u demo_user -p pingEnter the password at the prompt. An Access denied response establishes that MySQL answered, but the login still needs the 1045 checks.
- Start the MySQL service if it is stopped.
- Check the TCP port and
bind-addressin the server configuration. - Compare those settings with Host and Port in TableAI.
- 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.
Check Docker or a local proxy
Section titled “Check Docker or a local proxy”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.
Check a remote route
Section titled “Check a remote route”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.
How TableAI shows it
Section titled “How TableAI shows it”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.