Connect to Percona Server for MySQL¶
In this tutorial, you will connect to the Percona Server for MySQL you deployed previously.
The Operator creates a dedicated Secret named <cluster_name>-psuser-root that contains all connection details for the root user: hostname, port, username, password, and ready-to-use URIs. The Operator keeps this Secret up to date on every reconciliation.
Here’s how to connect:
-
Export the namespace, cluster name and the Secret name as environment variables:
export NAMESPACE=my-namespace export CLUSTER_NAME=ps-cluster1 export SECRET_NAME=${CLUSTER_NAME}-psuser-rootReplace
ps-cluster1with the name of your cluster if you changed it during installation. -
Verify that the connection Secret exists:
kubectl get secret $SECRET_NAME -n $NAMESPACELook for the Secret named
<cluster_name>-psuser-root. The default name differs on how you installed the Operator:ps-cluster1-psuser-rootmy-db-ps-db-psuser-root -
Retrieve the user credentials from the Secret:
kubectl get secret "$SECRET_NAME" -n "$NAMESPACE" \ -o jsonpath='{.data.user}' | base64 --decode && echo kubectl get secret "$SECRET_NAME" -n "$NAMESPACE" \ -o jsonpath='{.data.password}' | base64 --decode && echo -
Run a container with the
mysqlclient and connect its console output to your terminal. The following command does this, naming the new Podpercona-client:kubectl run -n $NAMESPACE -i --rm --tty percona-client \ --image=percona/percona-server:8.4 --restart=Never -- bash -ilExecuting it may require some time to deploy the corresponding Pod.
-
Connect to Percona Server for MySQL. To do this, run
mysqltool in thepercona-clientcommand shell using your cluster name and the password obtained from the secret instead of the<root_password>placeholder. The command will look different depending on whether your cluster uses load balancing with HAProxy (the default behavior) or uses MySQL Router (can be used with Group Replication clusters only):mysql -h <cluster_name>-haproxy -uroot -p'<root_password>'mysql -h <cluster_name>-router -uroot -p'<root_password>'
Congratulations! You have connected to Percona Server for MySQL.
Next steps¶
Created: March 25, 2024