@@ -4,9 +4,11 @@ password_change() {
4
4
# Set the password for MySQL user and root everytime this container is started.
5
5
# This allows to change the password by editing the deployment configuration.
6
6
if [[ -v MYSQL_USER && -v MYSQL_PASSWORD ]]; then
7
+ log_debug " About to change password for user '${MYSQL_USER} '."
7
8
mysql $mysql_flags << EOSQL
8
9
SET PASSWORD FOR '${MYSQL_USER} '@'%' = PASSWORD('${MYSQL_PASSWORD} ');
9
10
EOSQL
11
+ log_debug ' Password for user ' ${MYSQL_USER} ' changed.'
10
12
fi
11
13
12
14
# The MYSQL_ROOT_PASSWORD is optional, therefore we need to either enable remote
@@ -15,13 +17,14 @@ EOSQL
15
17
# GRANT will create a user if it doesn't exist on 5.6 and lower, but we
16
18
# need to explicitly call CREATE USER in 5.7 and higher
17
19
# then set its password
20
+ log_debug " About to change password for user 'root'."
18
21
if [ " $MYSQL_VERSION " \> " 5.6" ] ; then
19
22
mysql $mysql_flags << EOSQL
20
23
CREATE USER IF NOT EXISTS 'root'@'%';
21
24
EOSQL
22
25
fi
23
26
mysql $mysql_flags << EOSQL
24
- GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD} ' WITH GRANT OPTION;
27
+ GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD} ' WITH GRANT OPTION;
25
28
EOSQL
26
29
else
27
30
if [ " $MYSQL_VERSION " \> " 5.6" ] ; then
@@ -38,11 +41,15 @@ mysql $mysql_flags <<EOSQL
38
41
FLUSH PRIVILEGES;
39
42
EOSQL
40
43
fi
44
+ log_debug " Password for 'root' user changed."
41
45
fi
42
46
}
43
47
44
48
if ! [ -v MYSQL_RUNNING_AS_SLAVE ] ; then
45
- password_change
49
+ if ! password_change ; then
50
+ log_info " Changing password failed."
51
+ return 1
52
+ fi
46
53
fi
47
54
48
55
unset -f password_change
0 commit comments