You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mysql -h {{.DatabaseHostname}} -u {{.DatabaseAdminUsername}} -P 3306 -e "GRANT ALL PRIVILEGES ON {{.DatabaseName}}.* TO '{{.UserName}}'@'localhost' IDENTIFIED BY '$DatabasePassword'{{.RequireTLS}};GRANT ALL PRIVILEGES ON {{.DatabaseName}}.* TO '{{.UserName}}'@'%' IDENTIFIED BY '$DatabasePassword'{{.RequireTLS}};"
10
+
GRANT_DATABASE="{{.DatabaseName}}"
9
11
else
10
-
mysql -h {{.DatabaseHostname}} -u {{.DatabaseAdminUsername}} -P 3306 -e "GRANT ALL PRIVILEGES ON *.* TO '{{.UserName}}'@'localhost' IDENTIFIED BY '$DatabasePassword'{{.RequireTLS}};GRANT ALL PRIVILEGES ON *.* TO '{{.UserName}}'@'%' IDENTIFIED BY '$DatabasePassword'{{.RequireTLS}};"
12
+
GRANT_DATABASE="*"
11
13
fi
12
14
15
+
# going for maximum compatibility here:
16
+
# 1. MySQL 8 no longer allows implicit create user when GRANT is used
17
+
# 2. MariaDB has "CREATE OR REPLACE", but MySQL does not
18
+
# 3. create user with CREATE but then do all password and TLS with ALTER to
19
+
# support updates
20
+
21
+
$MYSQL_CMD<<EOF
22
+
CREATE USER IF NOT EXISTS '{{.UserName}}'@'localhost';
23
+
CREATE USER IF NOT EXISTS '{{.UserName}}'@'%';
24
+
25
+
ALTER USER '{{.UserName}}'@'localhost' IDENTIFIED BY '$DatabasePassword'{{.RequireTLS}};
26
+
ALTER USER '{{.UserName}}'@'%' IDENTIFIED BY '$DatabasePassword'{{.RequireTLS}};
27
+
28
+
GRANT ALL PRIVILEGES ON ${GRANT_DATABASE}.* TO '{{.UserName}}'@'localhost';
29
+
GRANT ALL PRIVILEGES ON ${GRANT_DATABASE}.* TO '{{.UserName}}'@'%';
30
+
EOF
31
+
32
+
13
33
# search for the account. not using SHOW CREATE USER to avoid displaying
14
34
# password hash
15
-
username=$(mysql -h {{.DatabaseHostname}} -u {{.DatabaseAdminUsername}} -P 3306 -NB -e "select user from mysql.user where user='{{.UserName}}' and host='localhost';")
35
+
username=$($MYSQL_CMD -NB -e "select user from mysql.user where user='{{.UserName}}' and host='localhost';")
0 commit comments