When I deploy a MySQL, it need a data dir. So i monut a pvc. But when the pod start, it is error. The message below.
This is because mysql is probably running as the mysql user, and the pvc is owned by root.
The only way I found to get around this, is to use a sub-directory inside the pvc.
- Scale down your mysql workload
- Create another container (Ubuntu) in the same namespace, and then mount the pvc in that container.
- Exec into the Ubuntu container, and cd to the pvc volume. Create a directory called
data, and change the ownership of the directory to the UID that mysql runs as.
- Turn off the Ubuntu pod, and then modify the mysql workload’s volume mount and set the
Sub Path in Volumeto the
datadirectory from step 3 and start mysql.