Installing MySql on Linux in a programmatic way. How to set the password?

2

I'm creating a sh file to start a Linux programming environment to automate this boot process. I usually just run the following command lines and during the MySql installation process I have to choose the ROOT user password.

This is the code:

//Iniciar sessão como super usuário para não escrever senha todo o tempo.
sudo su #MyPassword#
//Limpar a tela
clear

//Fazer a atualização do apt-get.
apt-get update
//Limpar a tela
clear

//Instalar MySql Server
apt install mysql-server
//Escolher a senha para root. OK
//Limpar a tela
clear

How do I pass the mysql installation statement and get the root password at the same time?

    
asked by anonymous 30.06.2016 / 02:26

1 answer

2

Change your .sh and add:

echo "mysql-server-5.6 mysql-server/root_password password senha_aqui" | sudo debconf-set-selections
echo "mysql-server-5.6 mysql-server/root_password_again password senha_aqui" | sudo debconf-set-selections
apt-get -y install mysql-server-5.6

There is documentation on debconf-set-selections in Ubuntu, which is a way to define and store values for use in non-interactive scripts.

Source¹ Font²

    

30.06.2016 / 03:00