Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am installing MySQL via the command line: sudo apt-get install mysql-server. During the installation process, it prompts me for a root password.

How can I specify the MySQL password without having to wait for the screen to pop up and ask me the password? Is there a parameter I can pass to apt-get to specify the MySQL root password so that I can write a script to perform the installation?

share|improve this question
up vote 3 down vote accepted

This should do it for you

echo mysql-server-5.1 mysql-server/root_password password PASSWORD | debconf-set-selections

echo mysql-server-5.1 mysql-server/root_password_again password PASSWORD | debconf-set-selections

apt-get install -y mysql-server

Obviously you would replace PASSWORD with whatever you would want your MySQL root password to be

share|improve this answer
Probably want to add -y to the install line for a scripted installation. – Shane Madden Oct 18 '11 at 1:57
Good catch Shane. I've edited my answer to reflect the change. – DKNUCKLES Oct 18 '11 at 2:02
perfect, thank you! I was not aware of the debconf-set-selections script. – rascher Oct 18 '11 at 2:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.