Skip to content

Instantly share code, notes, and snippets.

@xoxefdp
Created November 1, 2019 17:01
Show Gist options
  • Save xoxefdp/f5a0dfb61bc26cfd070f194c3c67100e to your computer and use it in GitHub Desktop.
Save xoxefdp/f5a0dfb61bc26cfd070f194c3c67100e to your computer and use it in GitHub Desktop.
MySQL installation script for debian based systems
#!/bin/bash
# Check if ran with root permissions
if [ "$(id -u)" != 0 ]; then
printf "The script must be run as root! (you can use sudo) \n"
exit 1
fi
if [[ $# -eq 1 ]]; then
DBPASSWORD=$1
printf "EXECUTING --> apt install -y --install-recommends mysql-client mysql-common \n"
apt install -y --install-recommends mysql-client mysql-common
printf "EXECUTING --> export DEBIAN_FRONTEND='noninteractive' \n"
export DEBIAN_FRONTEND="noninteractive"
printf "EXECUTING --> echo 'mysql-server mysql-server/root_password password $DBPASSWORD' | debconf-set-selections \n"
echo "mysql-server mysql-server/root_password password $DBPASSWORD" | debconf-set-selections
printf "EXECUTING --> echo 'mysql-server mysql-server/root_password_again password $DBPASSWORD' | debconf-set-selections \n"
echo "mysql-server mysql-server/root_password_again password $DBPASSWORD" | debconf-set-selections
printf "EXECUTING --> apt install -y --install-recommends mysql-server \n"
apt install -y --install-recommends mysql-server
# printf "mysql_secure_installation \n"
# mysql_secure_installation
printf "INSTALLING MySQL Client and Server DONE \n"
exit 0
else
printf "Missing password for database root user \n"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment