How to connect MySQL running on Kubernetes

Try the kubectl port-forward command.

In your case; kubectl port-forward app-mysql-3323704556-nce3w 3306:3306

See The documentation for all available options.


There are 2 steps involved:

1 ) You first perform port forwarding from localhost to your pod:

kubectl port-forward <your-mysql-pod-name> 3306:3306 -n <your-namespace>

2 ) Connect to database:

mysql -u root -h 127.0.0.1 -p <your-password>
 

Notice that you might need to change 127.0.0.1 to localhost - depends on your setup.

If host is set to:
localhost - then a socket or pipe is used.
127.0.0.1 - then the client is forced to use TCP/IP.

You can check if your database is listening for TCP connections with netstat -nlp.


Read more in:

Cant connect to local mysql server through socket tmp mysql sock

Can not connect to server