Skip to content

Commit

Permalink
Do not drop all users when a MySQL server starts
Browse files Browse the repository at this point in the history
This would remove the 'test' user created by Trillian's resetdb.sh script.
Instead, only create users if necessary, otherwise simply update them.
  • Loading branch information
Rob Percival authored and RJPercival committed May 19, 2017
1 parent 807a4dd commit 89a2fd7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions storage/mysql/kubernetes/image/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,22 @@ fi
INIT_SQL=$(mktemp)
chmod 0600 "${INIT_SQL}"

# Create the following users:
# Create/alter the following users:
# - root user for administrative purposes.
# - dummy user with no password or rights, for use by health checks.
# - SST user for use by Galera to replicate database state between nodes.
# TODO(robpercival): Restrict root access.
cat > "$INIT_SQL" <<EOSQL
DELETE FROM mysql.user;
CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}';
DROP USER IF EXISTS 'root'@'localhost';
ALTER USER IF EXISTS 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}';
CREATE USER IF NOT EXISTS 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}';
GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION;
CREATE USER 'dummy'@'localhost';
CREATE USER IF NOT EXISTS 'dummy'@'localhost';
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'dummy'@'localhost';
CREATE USER '${WSREP_SST_USER}'@'localhost' IDENTIFIED BY '${WSREP_SST_PASSWORD}';
ALTER USER IF EXISTS '${WSREP_SST_USER}'@'localhost' IDENTIFIED BY '${WSREP_SST_PASSWORD}';
CREATE USER IF NOT EXISTS '${WSREP_SST_USER}'@'localhost' IDENTIFIED BY '${WSREP_SST_PASSWORD}';
GRANT PROCESS, RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO '${WSREP_SST_USER}'@'localhost';
FLUSH PRIVILEGES;
EOSQL
Expand Down

0 comments on commit 89a2fd7

Please sign in to comment.