Skip to content

Commit 960a5cc

Browse files
authored
Merge pull request #1002 from newrelic/fix/mysql-5.6-create-user
fix: Mysql 5.6 create user
2 parents 144a500 + 4d0f0ea commit 960a5cc

File tree

3 files changed

+56
-29
lines changed

3 files changed

+56
-29
lines changed

recipes/newrelic/infrastructure/ohi/mysql/debian.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,17 @@ install:
179179
fi
180180
181181
# Create new user with needed permissions, delete any previous user if exists
182-
if [ -f /tmp/sql-create-user.sql ]; then
183-
sudo rm -f /tmp/sql-create-user.sql
184-
fi
185-
sudo tee -a /tmp/sql-create-user.sql > /dev/null <<"EOT"
186-
DROP USER IF EXISTS 'NEW_RELIC_MYSQL_USERNAME'@'localhost';
182+
sudo tee /tmp/sql-drop-user.sql > /dev/null <<"EOT"
183+
DROP USER 'NEW_RELIC_MYSQL_USERNAME'@'localhost';
184+
EOT
185+
186+
sudo tee /tmp/sql-create-user.sql > /dev/null <<"EOT"
187187
CREATE USER 'NEW_RELIC_MYSQL_USERNAME'@'localhost' IDENTIFIED BY 'NEW_RELIC_MYSQL_PASSWORD';
188-
GRANT REPLICATION CLIENT ON *.* TO 'NEW_RELIC_MYSQL_USERNAME'@'localhost';
189-
GRANT SELECT ON *.* TO 'NEW_RELIC_MYSQL_USERNAME'@'localhost';
188+
GRANT REPLICATION CLIENT ON *.* TO 'newrelic'@'localhost';
189+
GRANT SELECT ON *.* TO 'newrelic'@'localhost';
190190
EOT
191+
192+
sudo sed -i 's/NEW_RELIC_MYSQL_USERNAME/'$NEW_RELIC_MYSQL_USERNAME'/g' /tmp/sql-drop-user.sql
191193
sudo sed -i 's/NEW_RELIC_MYSQL_USERNAME/'$NEW_RELIC_MYSQL_USERNAME'/g' /tmp/sql-create-user.sql
192194
sudo sed -i 's/NEW_RELIC_MYSQL_PASSWORD/'$NEW_RELIC_MYSQL_PASSWORD'/g' /tmp/sql-create-user.sql
193195
@@ -204,6 +206,7 @@ install:
204206
read -r USERNAME
205207
USERNAME=${USERNAME:-root}
206208
209+
sudo mysql -u $USERNAME --port $NEW_RELIC_MYSQL_PORT -p$NEW_RELIC_MYSQL_ROOT_PASSWORD < /tmp/sql-drop-user.sql &> /dev/null ||:
207210
EXEC_OUTPUT=$(eval sudo mysql -u $USERNAME --port $NEW_RELIC_MYSQL_PORT -p$NEW_RELIC_MYSQL_ROOT_PASSWORD < /tmp/sql-create-user.sql 2>&1)
208211
echo "MySqlOutput:"$EXEC_OUTPUT | sudo tee -a {{.NEW_RELIC_CLI_LOG_FILE_PATH}} > /dev/null
209212
SQL_OUTPUT_ERROR=$(echo -n $EXEC_OUTPUT | grep "ERROR" | wc -l)
@@ -214,15 +217,18 @@ install:
214217
printf "\n\nThis installation was unable to create the required newrelic user.\nWe attempted to create the user with the SQL statement below.\nPerhaps the MySql root DB password is incorrect.\nPlease either re-run the installation with the correct root DB password, or follow the manual installation steps documented at https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/mysql-monitoring-integration/\n\n" >&2
215218
sudo cat /tmp/sql-create-user.sql
216219
sudo rm -f /tmp/sql-create-user.sql
220+
sudo rm -f /tmp/sql-drop-user.sql
217221
printf "\n"
218222
echo -e "detail:"$EXEC_OUTPUT
219223
printf "\n"
220224
exit 131
221225
fi
222226
else
223227
if [[ -z "$NEW_RELIC_MYSQL_ROOT_PASSWORD" ]]; then
228+
sudo mysql -u root --port $NEW_RELIC_MYSQL_PORT < /tmp/sql-drop-user.sql &> /dev/null ||:
224229
EXEC_OUTPUT=$(eval sudo mysql -u root --port $NEW_RELIC_MYSQL_PORT < /tmp/sql-create-user.sql 2>&1)
225230
else
231+
sudo mysql -u root --port $NEW_RELIC_MYSQL_PORT -p$NEW_RELIC_MYSQL_ROOT_PASSWORD < /tmp/sql-drop-user.sql &> /dev/null ||:
226232
EXEC_OUTPUT=$(eval sudo mysql -u root --port $NEW_RELIC_MYSQL_PORT -p$NEW_RELIC_MYSQL_ROOT_PASSWORD < /tmp/sql-create-user.sql 2>&1)
227233
fi
228234
echo "MySqlOutput:"$EXEC_OUTPUT | sudo tee -a {{.NEW_RELIC_CLI_LOG_FILE_PATH}} > /dev/null
@@ -231,13 +237,15 @@ install:
231237
printf "\n\nThis installation was unable to create the required newrelic user.\nWe attempted to create the user with the SQL statement below.\nPlease follow the manual installation steps documented at https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/mysql-monitoring-integration/ \n\n" >&2
232238
sudo cat /tmp/sql-create-user.sql
233239
sudo rm -f /tmp/sql-create-user.sql
240+
sudo rm -f /tmp/sql-drop-user.sql
234241
printf "\n"
235242
echo -e "detail:"$EXEC_OUTPUT
236243
printf "\n"
237244
exit 131
238245
fi
239246
fi
240247
sudo rm -f /tmp/sql-create-user.sql
248+
sudo rm -f /tmp/sql-drop-user.sql
241249
242250
# Install the integration
243251
sudo mkdir -p "/etc/newrelic-infra/integrations.d"

recipes/newrelic/infrastructure/ohi/mysql/rhel.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,17 @@ install:
168168
fi
169169
170170
# Create new user with needed permissions, delete any previous user if exists
171-
if [ -f /tmp/sql-create-user.sql ]; then
172-
sudo rm -f /tmp/sql-create-user.sql
173-
fi
174-
sudo tee -a /tmp/sql-create-user.sql > /dev/null <<"EOT"
175-
DROP USER IF EXISTS 'NEW_RELIC_MYSQL_USERNAME'@'localhost';
171+
sudo tee /tmp/sql-drop-user.sql > /dev/null <<"EOT"
172+
DROP USER 'NEW_RELIC_MYSQL_USERNAME'@'localhost';
173+
EOT
174+
175+
sudo tee /tmp/sql-create-user.sql > /dev/null <<"EOT"
176176
CREATE USER 'NEW_RELIC_MYSQL_USERNAME'@'localhost' IDENTIFIED BY 'NEW_RELIC_MYSQL_PASSWORD';
177-
GRANT REPLICATION CLIENT ON *.* TO 'NEW_RELIC_MYSQL_USERNAME'@'localhost';
178-
GRANT SELECT ON *.* TO 'NEW_RELIC_MYSQL_USERNAME'@'localhost';
177+
GRANT REPLICATION CLIENT ON *.* TO 'newrelic'@'localhost';
178+
GRANT SELECT ON *.* TO 'newrelic'@'localhost';
179179
EOT
180+
181+
sudo sed -i 's/NEW_RELIC_MYSQL_USERNAME/'$NEW_RELIC_MYSQL_USERNAME'/g' /tmp/sql-drop-user.sql
180182
sudo sed -i 's/NEW_RELIC_MYSQL_USERNAME/'$NEW_RELIC_MYSQL_USERNAME'/g' /tmp/sql-create-user.sql
181183
sudo sed -i 's/NEW_RELIC_MYSQL_PASSWORD/'$NEW_RELIC_MYSQL_PASSWORD'/g' /tmp/sql-create-user.sql
182184
@@ -193,6 +195,7 @@ install:
193195
read -r USERNAME
194196
USERNAME=${USERNAME:-root}
195197
198+
sudo mysql -u $USERNAME --port $NEW_RELIC_MYSQL_PORT -p$NEW_RELIC_MYSQL_ROOT_PASSWORD < /tmp/sql-drop-user.sql &> /dev/null ||:
196199
EXEC_OUTPUT=$(eval sudo mysql -u $USERNAME --port $NEW_RELIC_MYSQL_PORT -p$NEW_RELIC_MYSQL_ROOT_PASSWORD < /tmp/sql-create-user.sql 2>&1)
197200
echo "MySqlOutput:"$EXEC_OUTPUT | sudo tee -a {{.NEW_RELIC_CLI_LOG_FILE_PATH}} > /dev/null
198201
SQL_OUTPUT_ERROR=$(echo -n $EXEC_OUTPUT | grep "ERROR" | wc -l)
@@ -204,15 +207,18 @@ install:
204207
printf "\n\nThis installation was unable to create the required newrelic user.\nWe attempted to create the user with the SQL statement below.\nPerhaps the MySql root DB password is incorrect.\nPlease either re-run the installation with the correct root DB password, or follow the manual installation steps documented at https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/mysql-monitoring-integration/ \n\n" >&2
205208
sudo cat /tmp/sql-create-user.sql
206209
sudo rm -f /tmp/sql-create-user.sql
210+
sudo rm -f /tmp/sql-drop-user.sql
207211
printf "\n"
208212
echo -e "detail:"$EXEC_OUTPUT
209213
printf "\n"
210214
exit 131
211215
fi
212216
else
213217
if [[ -z "$NEW_RELIC_MYSQL_ROOT_PASSWORD" ]]; then
218+
sudo mysql -u root --port $NEW_RELIC_MYSQL_PORT < /tmp/sql-drop-user.sql &> /dev/null ||:
214219
EXEC_OUTPUT=$(eval sudo mysql -u root --port $NEW_RELIC_MYSQL_PORT < /tmp/sql-create-user.sql 2>&1)
215220
else
221+
sudo mysql -u root --port $NEW_RELIC_MYSQL_PORT -p$NEW_RELIC_MYSQL_ROOT_PASSWORD < /tmp/sql-drop-user.sql &> /dev/null ||:
216222
EXEC_OUTPUT=$(eval sudo mysql -u root --port $NEW_RELIC_MYSQL_PORT -p$NEW_RELIC_MYSQL_ROOT_PASSWORD < /tmp/sql-create-user.sql 2>&1)
217223
fi
218224
echo "MySqlOutput:"$EXEC_OUTPUT | sudo tee -a {{.NEW_RELIC_CLI_LOG_FILE_PATH}} > /dev/null
@@ -221,13 +227,15 @@ install:
221227
printf "\n\nThis installation was unable to create the required newrelic user.\nWe attempted to create the user with the SQL statement below.\nPlease follow the manual installation steps documented at https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/mysql-monitoring-integration/\n\n" >&2
222228
sudo cat /tmp/sql-create-user.sql
223229
sudo rm -f /tmp/sql-create-user.sql
230+
sudo rm -f /tmp/sql-drop-user.sql
224231
printf "\n"
225232
echo -e "detail:"$EXEC_OUTPUT
226233
printf "\n"
227234
exit 131
228235
fi
229236
fi
230237
sudo rm -f /tmp/sql-create-user.sql
238+
sudo rm -f /tmp/sql-drop-user.sql
231239
232240
# Install the integration
233241
sudo mkdir -p "/etc/newrelic-infra/integrations.d"

recipes/newrelic/infrastructure/ohi/mysql/suse.yml

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,24 +164,25 @@ install:
164164
fi
165165
166166
# Create new user with needed permissions, delete any previous user if exists
167-
if [ -f /tmp/sql-create-user.sql ]; then
168-
sudo rm -f /tmp/sql-create-user.sql
169-
fi
170-
171-
sudo tee -a /tmp/sql-create-user.sql > /dev/null <<"EOT"
172-
DROP USER IF EXISTS 'NR_CLI_DB_USERNAME'@'localhost';
173-
CREATE USER 'NR_CLI_DB_USERNAME'@'localhost' IDENTIFIED BY 'NR_CLI_DB_PASSWORD';
174-
GRANT REPLICATION CLIENT ON *.* TO 'NR_CLI_DB_USERNAME'@'localhost';
175-
GRANT SELECT ON *.* TO 'NR_CLI_DB_USERNAME'@'localhost';
167+
sudo tee /tmp/sql-drop-user.sql > /dev/null <<"EOT"
168+
DROP USER 'NEW_RELIC_MYSQL_USERNAME'@'localhost';
176169
EOT
177170
178-
sudo sed -i 's/NR_CLI_DB_USERNAME/'$NR_CLI_DB_USERNAME'/g' /tmp/sql-create-user.sql
179-
sudo sed -i 's/NR_CLI_DB_PASSWORD/'$NR_CLI_DB_PASSWORD'/g' /tmp/sql-create-user.sql
180-
if [ $MYSQL_ROOT_PASSWORD -gt 0 ] ; then
181-
182-
printf "MySql credential with permission to create user, and grant select/replication permission is required, please enter it below when prompted\n"
171+
sudo tee /tmp/sql-create-user.sql > /dev/null <<"EOT"
172+
CREATE USER 'NEW_RELIC_MYSQL_USERNAME'@'localhost' IDENTIFIED BY 'NEW_RELIC_MYSQL_PASSWORD';
173+
GRANT REPLICATION CLIENT ON *.* TO 'newrelic'@'localhost';
174+
GRANT SELECT ON *.* TO 'newrelic'@'localhost';
175+
EOT
176+
177+
sudo sed -i 's/NEW_RELIC_MYSQL_USERNAME/'$NEW_RELIC_MYSQL_USERNAME'/g' /tmp/sql-drop-user.sql
178+
sudo sed -i 's/NEW_RELIC_MYSQL_USERNAME/'$NEW_RELIC_MYSQL_USERNAME'/g' /tmp/sql-create-user.sql
179+
sudo sed -i 's/NEW_RELIC_MYSQL_PASSWORD/'$NEW_RELIC_MYSQL_PASSWORD'/g' /tmp/sql-create-user.sql
180+
181+
if [[ $MYSQL_ROOT_PASSWORD -gt 0 && "$NEW_RELIC_ASSUME_YES" != "true" ]] ; then
183182
TRIES=0
183+
printf "MySql credential with permission to create user, and grant select/replication permission is required, please enter it below when prompted\n"
184184
SQL_OUTPUT_ERROR=1
185+
185186
while [ $TRIES -lt {{.MAX_RETRIES}} ] && [ $SQL_OUTPUT_ERROR -gt 0 ] ;
186187
do
187188
if [ $TRIES -gt 0 ]; then printf "\nPlease try again\n"; fi
@@ -190,6 +191,7 @@ install:
190191
read -r USERNAME
191192
USERNAME=${USERNAME:-root}
192193
194+
sudo mysql -u $USERNAME --port $NEW_RELIC_MYSQL_PORT -p$NEW_RELIC_MYSQL_ROOT_PASSWORD < /tmp/sql-drop-user.sql &> /dev/null ||:
193195
EXEC_OUTPUT=$(eval sudo mysql -u $USERNAME --port $NR_CLI_DB_PORT -p$NR_CLI_DB_ROOT_PASSWORD < /tmp/sql-create-user.sql 2>&1)
194196
echo "MySqlOutput:"$EXEC_OUTPUT | sudo tee -a {{.NEW_RELIC_CLI_LOG_FILE_PATH}} > /dev/null
195197
SQL_OUTPUT_ERROR=$(echo -n $EXEC_OUTPUT | grep "ERROR" | wc -l)
@@ -200,26 +202,35 @@ install:
200202
printf "\n\nThis installation was unable to create the required newrelic user.\nWe attempted to create the user with the SQL statement below.\nPerhaps the MySql root DB password is incorrect.\nPlease either re-run the installation with the correct root DB password, or follow the manual installation steps documented at https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/mysql-monitoring-integration/\n\n" >&2
201203
sudo cat /tmp/sql-create-user.sql
202204
sudo rm -f /tmp/sql-create-user.sql
205+
sudo rm -f /tmp/sql-drop-user.sql
203206
printf "\n"
204207
echo -e "detail:"$EXEC_OUTPUT
205208
printf "\n"
206209
exit 131
207210
fi
208211
else
209-
EXEC_OUTPUT=$(eval sudo mysql -u root --port $NR_CLI_DB_PORT < /tmp/sql-create-user.sql 2>&1)
212+
if [[ -z "$NEW_RELIC_MYSQL_ROOT_PASSWORD" ]]; then
213+
sudo mysql -u root --port $NEW_RELIC_MYSQL_PORT < /tmp/sql-drop-user.sql &> /dev/null ||:
214+
EXEC_OUTPUT=$(eval sudo mysql -u root --port $NEW_RELIC_MYSQL_PORT < /tmp/sql-create-user.sql 2>&1)
215+
else
216+
sudo mysql -u root --port $NEW_RELIC_MYSQL_PORT -p$NEW_RELIC_MYSQL_ROOT_PASSWORD < /tmp/sql-drop-user.sql &> /dev/null ||:
217+
EXEC_OUTPUT=$(eval sudo mysql -u root --port $NEW_RELIC_MYSQL_PORT -p$NEW_RELIC_MYSQL_ROOT_PASSWORD < /tmp/sql-create-user.sql 2>&1)
218+
fi
210219
echo "MySqlOutput:"$EXEC_OUTPUT | sudo tee -a {{.NEW_RELIC_CLI_LOG_FILE_PATH}} > /dev/null
211220
SQL_OUTPUT_ERROR=$(echo -n $EXEC_OUTPUT | grep "ERROR" | wc -l)
212221
if [ $SQL_OUTPUT_ERROR -gt 0 ] ; then
213222
printf "\n\nThis installation was unable to create the required newrelic user.\nWe attempted to create the user with the SQL statement below.\nPlease follow the manual installation steps documented at https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/mysql-monitoring-integration/\n\n" >&2
214223
sudo cat /tmp/sql-create-user.sql
215224
sudo rm -f /tmp/sql-create-user.sql
225+
sudo rm -f /tmp/sql-drop-user.sql
216226
printf "\n"
217227
echo -e "detail:"$EXEC_OUTPUT
218228
printf "\n"
219229
exit 131
220230
fi
221231
fi
222232
sudo rm -f /tmp/sql-create-user.sql
233+
sudo rm -f /tmp/sql-drop-user.sql
223234
224235
# Install the integration
225236
sudo mkdir -p "/etc/newrelic-infra/integrations.d"

0 commit comments

Comments
 (0)