Last active
May 31, 2024 14:19
-
-
Save Mins/4602864 to your computer and use it in GitHub Desktop.
Automating mysql_secure_installation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 (enter for none):\" | |
send \"$MYSQL\r\" | |
expect \"Change the root password?\" | |
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 |
Amazing work!! thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Manny thanks, it works on Debian 10 buster