Connect database in the testing environment
Procedure 1. Use kubectl exec command
If the database address is not required, run the command below to connect to the cluster via the default address.
Get the
username
andpassword
for the cluster.kubectl get secrets -n demo mycluster-conn-credential -o jsonpath='{.data.\username}' | base64 -d
>
root
kubectl get secrets -n demo mycluster-conn-credential -o jsonpath='{.data.\password}' | base64 -d
>
2gvztbvzRun the
kubectl exec
command and specify the pod to be connected.kubectl exec -ti -n demo mycluster-mysql-0 -- bash
Connect to the cluster.
mysql -u root -p2gvztbvz
Procedure 2. Connect database with CLI or SDK client
For a pod without a client, you can follow the steps below to connect to the cluster. You can also connect to the cluster by other options, like CLI, SDK client, go connection, java connection, etc.
Below is an example of using CLI to connect to the cluster on the local host.
Get the
username
andpassword
for the cluster.kubectl get secrets -n demo mycluster-conn-credential -o jsonpath='{.data.\username}' | base64 -d
>
root
kubectl get secrets -n demo mycluster-conn-credential -o jsonpath='{.data.\password}' | base64 -d
>
2gvztbvzRun the command below to connect to the cluster.
kubectl port-forward svc/mycluster-mysql 3306:3306 -n demo
mysql -h 127.0.0.1 -P 3306 -u root -p2gvztbvz