Skip to content

Instantly share code, notes, and snippets.

@nalipaz
Forked from Mins/mysql_secure.sh
Last active June 3, 2016 22:29
Show Gist options
  • Save nalipaz/1e091028d49f9a9c010fd82d6617be7f to your computer and use it in GitHub Desktop.
Save nalipaz/1e091028d49f9a9c010fd82d6617be7f to your computer and use it in GitHub Desktop.
Automating mysql_secure_installation on MariaDB in CentOS 7
#!/bin/bash
yum -y install expect
MARIADB_ROOT_PASS=abcd1234
SECURE_MYSQL=$(expect -c "
set timeout 3
spawn mysql_secure_installation
expect \"Enter current password for root (enter for none):\"
send \"\r\"
expect \"Set root password? \[Y/n\]\"
send \"y\r\"
expect \"New password:\"
send \"${MARIADB_ROOT_PASS}\r\"
expect \"Re-enter new password:\"
send \"${MARIADB_ROOT_PASS}\r\"
expect \"Remove anonymous users? \[Y/n\]\"
send \"y\r\"
expect \"Disallow root login remotely? \[Y/n\]\"
send \"n\r\"
expect \"Remove test database and access to it? \[Y/n\]\"
send \"y\r\"
expect \"Reload privilege tables now? \[Y/n\]\"
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