Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automating mysql_secure_installation for MySQL 5.7
#!/bin/bash
aptitude -y install expect
// Not required in actual script
MYSQL_ROOT_PASSWORD=abcd1234
SECURE_MYSQL=$(expect -c "
set timeout 10
spawn mysql_secure_installation
expect \"Enter current password for root:\"
send \"$MYSQL\r\"
expect \"Would you like to setup VALIDATE PASSWORD plugin?\"
send \"n\r\"
expect \"Change the password for root ?\"
send \"n\r\"
expect \"Remove anonymous users?\"
send \"y\r\"
expect \"Disallow root login remotely?\"
send \"y\r\"
expect \"Remove test database and access to it?\"
send \"y\r\"
expect \"Reload privilege tables now?\"
send \"y\r\"
expect eof
")
echo "$SECURE_MYSQL"
aptitude -y purge expect
@mansouryaacoubi

This comment has been minimized.

Copy link

mansouryaacoubi commented Jun 6, 2017

You should change this:

expect \"Enter current password for root:\"
send \"$MYSQL\r\"

to this

expect \"Enter current password for root:\"
send \"$MYSQL_ROOT_PASSWORD\r\"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.