Update MySQL bash installation script

This commit is contained in:
Johan 2022-12-19 09:04:52 +01:00
parent 61cdfb971c
commit b9510e9f55

View File

@ -1,15 +1,27 @@
# Install using: sudo su -c "bash <(wget -qO- /url/to/install-bind.sh)"
REALUSER=$(logname)
apt update 2>>install.log
if systemctl status mysql.service | grep -q 'Unit mysql.service could not be found'; then
echo "Installing MySQL..."
apt apt install mysql-server -y 2>>install.log &&
systemctl start mysql.service 2>>install.log
echo Running apt update...
apt -qq update 2>>install.log
if ! [ -f /etc/init.d/mysql* ]; then
echo "Installing MySQL..."
apt install mysql-server -y 2>>install.log
ufw allow 3306 2>>install.log
systemctl start mysql.service 2>>install.log
fi
systemctl status mysql.service
echo 'Installation complete'
if ! grep -q "# bind-address = 127.0.0.1" "/etc/mysql/mysql.conf.d/mysqld.cnf"; then
sed -i '/^bind\-address/s/^/#/' /etc/mysql/mysql.conf.d/mysqld.cnf
fi
read -e -p "Enter desired root password:" ROOTPASSWORD
if mysql -e "SELECT user,host FROM mysql.user WHERE host = '%';" | grep -q 'root'; then
echo "Altering root user with password $ROOTPASSWORD"
mysql -e "ALTER USER 'root'@'%' IDENTIFIED BY '$ROOTPASSWORD';"
else
echo "Adding root user with password $ROOTPASSWORD"
mysql -e "CREATE USER 'root'@'%' IDENTIFIED BY '$ROOTPASSWORD';"
fi
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;"
mysql -e "FLUSH PRIVILEGES;"
mysql -e "SELECT user,host FROM mysql.user;"
systemctl restart mysql.service
echo 'Installation complete'