From b9510e9f55efc4d17e3d60e32a72bdd7ee82c5ee Mon Sep 17 00:00:00 2001 From: Johan Date: Mon, 19 Dec 2022 09:04:52 +0100 Subject: [PATCH] Update MySQL bash installation script --- BashScripts/install-mysql.sh | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/BashScripts/install-mysql.sh b/BashScripts/install-mysql.sh index e703ff5..2641465 100644 --- a/BashScripts/install-mysql.sh +++ b/BashScripts/install-mysql.sh @@ -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' \ No newline at end of file +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'