9

I am setting up a bash script to automate the building of a LAMP environment.

I am using debconf-set-selections to set options before installing mysql, phpmyadmin, etc ...

It works mainly great. But the problem is that I have to set an empty password for mysql and it still asks for the password during installation even with the lines typed before :

echo "mysql-server-5.5  mysql-server/root_password  password" | debconf-set-selections
echo "mysql-server-5.5  mysql-server/root_password_again    password" | debconf-set-selections
Yoel
  • 9,144
  • 7
  • 42
  • 57
piroux
  • 341
  • 3
  • 11

4 Answers4

10

Currently, it is possible to do this, but it's a little tricky.

You have to explicitly set quotes to mark an empty password, like this:

sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password \"''\""

Just tested on Ubuntu 15.10, works like a charm.

Soullivaneuh
  • 3,553
  • 3
  • 37
  • 71
8

The recommended approach for setting an empty password during mysql-server's package installation process using debconf-set-selections depends on the package version in hand.

  • MySQL 5.7

    Although it's possible to configure the password to be empty, the installation process will automatically enable the authentication plugin auth_socket in such a case. Hence, the password-less login shall be conditioned on using UNIX socket based authentication (e.g. requiring the login to be made from the user account root on the local machine).

    • For the package provided by the MySQL APT repository:

      sudo debconf-set-selections <<< "mysql-community-server mysql-community-server/root-pass password "
      sudo debconf-set-selections <<< "mysql-community-server mysql-community-server/re-root-pass password "
      
    • For the package provided by the Ubuntu package repositories:

      sudo debconf-set-selections <<< "mysql-server mysql-server/root-password password "
      sudo debconf-set-selections <<< "mysql-server mysql-server/root-password_again password "
      
  • MySQL 5.5 and MySQL 5.6

    The solution suggested by this answer should work, with a minor addition that confirms the empty password:

    sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password \"''\""
    sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password \"''\""
    

A fallback solution

If all approaches fail, it's possible to circumvent the issue and implicitly leave the password blank by preventing debconf from asking the user for a password altogether. Unfortunately, this applies to all questions, rather than just the password-related ones.

Here are two methods that achieve the desired result:

  • Set debconf's frontend to noninteractive:

    DEBIAN_FRONTEND=noninteractive apt-get install [-y] [-q] mysql-server
    
  • Set debconf's priority level to critical:

    DEBIAN_PRIORITY=critical apt-get install [-y] [-q] mysql-server
    

    This method is probably preferable as it permits the display of critical messages.

Yoel
  • 9,144
  • 7
  • 42
  • 57
  • I forgot that I had asked this question. One year ago, I resolved it with the "DEBIAN_FRONTEND=noninteractive" way and I have been happy with it since then. – piroux Nov 19 '15 at 12:33
  • "Although it's possible to configure the password to be empty, the installation process will automatically enable the authentication plugin auth_socket in such a case. " -- this is a colossal nuisance, so much I have commented out the `ALTER` from `/var/lib/dpkg/info/mysql-server-8.0.postinst` and added a divert so it doesn't get overwritten: `sudo dpkg-divert --divert /var/lib/dpkg/info/mysql-server-8.0.postinst.packaged --rename /var/lib/dpkg/info/mysql-server-8.0.postinst` – chx Jul 09 '22 at 07:46
3

i think that your problem is that right before 'password' you need to add the word 'string' like this:

echo "mysql-server-5.5  mysql-server/root_password string password" | debconf-set-selections

btw this does the same thing but i think its cool:

debconf-set-selections <<< "mysql-server-5.5  mysql-server/root_password string password"
0

Try actually adding an empty argument

echo mysql-server-5.5 mysql-server/root_password password "" | debconf-set-selections
echo mysql-server-5.5 mysql-server/root_password_again password "" | debconf-set-selections
Felix Frank
  • 8,125
  • 1
  • 23
  • 30