Codementor Events

Setting a root password on mysql in silent mode in ubuntu

Published Jan 22, 2017

Setting a root password on mysql in silent mode in ubuntu

If you want to install mysql (or a stack with mysql) and want to set a root password on it,

You usually want to do this to provison servers, or for unattended installation.

Doing so is fairly simple

sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password your_password'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password your_password'
sudo apt-get -y install mysql-server

If your prompt doesn't support here-strings


echo "mysql-server mysql-server/root_password password your_password" | debconf-set-selections
echo "mysql-server mysql-server/root_password_again password your_password" | debconf-set-selections

Discover and read more posts from Somi
get started
post commentsBe the first to share your opinion
Show more replies