Reference: How to pass password to mysql command line
I want to grab returned metadata from an AWS EC2 instance and set a new mysql password based on this data.
I need assistance with the script which will run as first boot.
#!/bin/bash
output=$(ec2metadata --instance-id); Used for storing EC2 ID.
mysql -u root -pOldPassword
UPDATE mysql.user
Now pass instance-id and use it to set a new password for mysql root.
SET authentication_string = PASSWORD('$output'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
EXIT
iid=$(ec2metadata --instance-id)
? – Jeff Schaller May 25 '17 at 16:17output=$(ec2metadata --instance-id)
then I use amy.cnf
to set MySQL credentials to allow bash:UPDATE mysql.user SET authentication_string = PASSWORD($output),
but it fails here as I don't know the correct syntax for MySQL to accept a bash variable. – drew_satellite May 26 '17 at 19:25