I have a MySQL database dump file, and I want to copy it to a Kubernetes pod running a MySQL image in AKS, so that I can import the database.
I first created an Azure Blob Container, configured it as a Persistent Volume (PV), set up the Persistent Volume Claim (PVC) from the PV, and then mounted it to /var/lib/mysql in the pod that ran the MySQL image.
Since MySQL was very strict that /var/lib/mysql must be empty when MySQL started to create a new and empty database, I kept the Blob Container empty, and let the pod start (so that an empty database was created) before uploading the database dump file to the Blob Container (i.e. the dump file was copied to /var/lib/mysql of the MySQL pod). I then tried to login to the pod using:
kubectl exec -it <pod_name> -- /bin/bash
Next, I tried to import the database by running:
cd /var/lib/mysql
mysql -u root -p <db_name> < <database_dump_file_name>
But I got the permission denied error, because the database dump file had root user ownership and 640 permission, but the MySQL pod had to run as User ID 1000 and Group ID 999, meaning that I could not change the ownership and permission of the database dump file. What can I do to get rid of the permission denied error?
I found a clumsy solution, the essence is to run another pod as root without MySQL, and change the database dump file's ownership and permission there:
kubectl delete.kubectl apply.kubectl exec -it pod/<pod_name> -- /bin/bashkubectl delete.