Created
November 5, 2019 13:28
-
-
Save iamcryptoki/f65cea21280c19bf016456acefb675dc to your computer and use it in GitHub Desktop.
Export MySQL database from Kubernetes pod.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Export dump particular database. | |
$ kubectl exec {{podName}} -n {{namespace}} -- mysqldump -u {{dbUser}} -p{{password}} {{DatabaseName}} > <scriptName>.sql | |
# Export dump all databases. | |
$ kubectl exec {{podName}} -n {{namespace}} -- mysqldump -u {{dbUser}} -p{{password}} --all-databases > <scriptName>.sql | |
# Restore a database from a dump. | |
$ kubectl exec -it {{podName}} -n {{namespace}} -- mysql -u {{dbUser}} -p{{password}} {{DatabaseName}} < <scriptName>.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I was trying to export, I ran into a permission denied issue and this is how I worked around it, hope this helps someone:
Login into the pod
kubectl exec -it <pod> -n <namespace> -- /bin/bash
run mysqldump from within the pod and use
tmp
to write the filemysqldump <-u user> -p <db> > /tmp/file.sql
Copy the file from the pod
kubectl cp <namespace>/<pod>:/tmp/file.sql file.sql