Installing Mysql on linux programmatically. How to set the password?

Asked

Viewed 91 times

2

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

That 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 instruction and tbm the root password at the same time?

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 the debconf-set-selections in Ubuntu, which is a way to define and store values to use in non-interactive scripts.

Font¹ Source² Source³

Browser other questions tagged

You are not signed in. Login or sign up in order to post.