<p>I have the following deployment which puts up MySQL instance:</p>

<pre><code>kind: Deployment
apiVersion: apps/v1beta1
metadata:
  name: mysql
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: mysql:8
        ports:
        - containerPort: 3306
        env:
          - name: MYSQL_ROOT_PASSWORD
            valueFrom:
              secretKeyRef:
                name: mysql-root-password
                key: password
</code></pre>

<p>The password is just <code>root</code> :</p>

<pre><code>kind: Secret
apiVersion: v1
metadata:
  name: mysql-root-password
type: Opaque
data:
  password: cm9vdA==
</code></pre>

<p><strong>The problem is I try to connect to the instance after port forwarding the MySQL port, following the instructions from <a href="https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/" rel="nofollow noreferrer">here</a>, but get an error:</strong></p>

<pre><code>$ kubectl port-forward mysql-824284009-rpbpk 3306
Forwarding from 127.0.0.1:3306 -&gt; 3306
Forwarding from [::1]:3306 -&gt; 3306

# from another terminal
$ mysql -u root -p
Enter password:  
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
</code></pre>

<p>Connecting to the server from the pod itself works:</p>

<pre><code>$ kubectl exec -it mysql-824284009-rpbpk -- /bin/bash
root@mysql-824284009-rpbpk:/# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
...
mysql&gt;
</code></pre>

<p>I have basically the same setup like <a href="https://stackoverflow.com/questions/39910225/how-to-connect-mysql-running-on-kubernetes">here</a>, except I'm running the cluster in minikube instead of GCP.
My local MySQL is not runnning, so I assume there is no chance of clashing.</p>

<p>The port forwarding is likely there, but you need to tell mysql client to connect using host/port and not unix socket (default)</p>

<pre><code>mysql --host=localhost --protocol tcp --port=3306 -u root -p
</code></pre>

<p>If you don't, mysql by default uses local linux socket to connect to he server: /var/run/mysqld/mysqld.sock .. It even tells you so ;)</p>

<p><strong>Update:</strong> As Gabriel checked - adding <code>--protocol tcp</code> had finally made it works, so I am addding it to my answer</p>
