Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear
- read -p "Please enter your desired MySQL username: " USER
- echo $USER
- read -p "Please enter your desired MySQL password: " PASS
- echo $PASS
- read -p "Please enter your desired ROOT password: " ROOTPASS
- echo $ROOTPASS
- ########################################
- ### Secure MySQL Installation Script ###
- #######################################
- apt-get -y install expect
- MYSQL_ROOT_PASSWORD=$ROOTPASS
- 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"
- apt-get -y purge expect
- sleep 1
- ######################
- ### MySQL Commands ###
- ######################
- echo "
- CREATE USER '$USER'@'localhost' IDENTIFIED BY '$PASS';
- GRANT ALL PRIVILEGES ON *.* TO '$USER'@'localhost' WITH GRANT OPTION;
- CREATE USER '$USER'@'%' IDENTIFIED BY '$PASS';
- GRANT ALL PRIVILEGES ON *.* TO '$USER'@'%' WITH GRANT OPTION;
- FLUSH PRIVILEGES;" >> commands.sql
- mysql < "commands.sql"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement