Skip to content

Instantly share code, notes, and snippets.

@klevisndoka
Forked from Mins/mysql_secure.sh
Last active April 4, 2019 08:45
Show Gist options
  • Save klevisndoka/9f7bfd80a8782b22f1bbce548db2792b to your computer and use it in GitHub Desktop.
Save klevisndoka/9f7bfd80a8782b22f1bbce548db2792b to your computer and use it in GitHub Desktop.
Automating mysql_secure_installation
#!/bin/bash
yum -y install expect
MYSQL_ROOT_PASSWORD=root
SECURE_MYSQL=$(expect -c "
set timeout 10
spawn mysql_secure_installation
expect \"Enter current password for root (enter for none):\"
send \"\r\"
expect \"Set root password?\"
send \"y\r\"
expect \"New password:\"
send \"$MYSQL_ROOT_PASSWORD\r\"
expect \"Re-enter new password:\"
send \"$MYSQL_ROOT_PASSWORD\r\"
expect \"Remove anonymous users?\"
send \"y\r\"
expect \"Disallow root login remotely?\"
send \"n\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"
yum -y remove expect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment