Skip to content

MDEV-25497 now you can run "docker-entrypoint.sh mysqld --user=root" and it will work #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions 10.5/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ docker_verify_minimum_env() {
# also ensures permission for user mysql of run as root
docker_create_db_directories() {
local user; user="$(id -u)"

local args="$@"

# TODO other directories that are used by default? like /var/lib/mysql-files
# see https://github.com/docker-library/mysql/issues/562
mkdir -p "$DATADIR"

if [ "$user" = "0" ]; then
# chown fails in secure environments where container root only has as much privilege with files as the running user (eg: HPC singularity)
if [ "$user" = "0" ] && ! [[ "$args" == *"--user=root"* ]] ; then
# this will cause less disk access than `chown -R`
find "$DATADIR" \! -user mysql -exec chown mysql '{}' +
fi
Expand Down Expand Up @@ -320,10 +322,11 @@ _main() {
mysql_check_config "$@"
# Load various environment variables
docker_setup_env "$@"
docker_create_db_directories
docker_create_db_directories "$@"

# If container is started as root user, restart as dedicated mysql user
if [ "$(id -u)" = "0" ]; then
local args="$@"
# If container is started as root user without explicit intention, restart as dedicated mysql user
if [ "$(id -u)" = "0" ] && ! [[ "$args" == *"--user=root"* ]] ; then
mysql_note "Switching to dedicated user 'mysql'"
exec gosu mysql "$BASH_SOURCE" "$@"
fi
Expand Down