Mysql auto install stuck

I wrote a script to install some set of packages to a server list. When I execute a script mysql install, stuck at "enter root password" section. Is there anything I need to change in my script? Advise me.

Is there a way to pass the mysql root password through the script itself?

Below is the code I used

#!/usr/bin/env bash
read -p "Enter server name : " servername
echo "Installing package on $servername"
ssh "${servername}" sudo apt-get -y install apache2 mysql-server

      

Installation stuck here

Even if I enter the password, it will not proceed to the next step. I am very new to scripting. Let me know where the script can be changed.

+3


source to share


2 answers


#!/usr/bin/env bash
read -p "Enter server name : " servername
echo "Installing package on $servername"
ssh "${Host}" "echo 'mysql-server-5.7 mysql-server/root_password password your_password' | debconf-set-selections && \
echo 'mysql-server-5.7 mysql-server/root_password_again password your_password' | debconf-set-selections && \
apt-get update && \
apt-get -y install apache2 apache2-doc apache2-utils mysql-server"

      

The above code does the trick



Note : The backslash (\) is used for readability. They allow the command to continue on the next line.

0


source


apt-get

is the interface before dpkg

and debconf

and works interactively by default, does -y

n't even change that.

mysql-server

Installation requires that the root password be entered interactively during installation.

To completely automatically install MySQL server on a Debian based Linux distribution, you can enter non-interactive mode and preset the MySQL administrator password as follows.

In the shell where you want to start the process, run:



export DEBIAN_FRONTEND="noninteractive"

      

Then

apt-get install -y debconf-utils
debconf-set-selections <<< "mysql-server mysql-server/root_password yournewpassword"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again yournewpassword"
apt-get install -y mysql-server-5.6

      

+2


source







All Articles