11

I am trying create a shell call for non-interactive mysql 5.7 community server installation on ubuntu 14.04. According to various sources using debconf-set-selections should allow such an installation yet I am unable to launch non-interactive dpkg installer.

Bellow are the env variables that I am trying to use for non-interactive install

vagrant@default-ubuntu-1404:/sql$ echo $DEBIAN_FRONTEND 
noninteractive
vagrant@default-ubuntu-1404:/sql$ echo mysql-apt-config mysql-apt-config/enable-repo select mysql-5.7 | sudo debconf-set-selections

Here are all the mysql-apt-config settings for the system

vagrant@default-ubuntu-1404:/sql$ sudo debconf-get-selections | grep mysql
    mysql-apt-config    mysql-apt-config/select-tools   select  workbench-6.2 workbench-6.3 connector-python-2.0 connector-python-2.1 router-2.0 mysql-utilities-1.5 mysql-tools
    mysql-apt-config    mysql-apt-config/select-preview select  
    mysql-apt-config    mysql-apt-config/repo-distro    select  ubuntu
    mysql-apt-config    mysql-apt-config/enable-repo    select  mysql-5.7
    mysql-apt-config    mysql-apt-config/repo-url   string  http://repo.mysql.com/apt/
    # Choices: MySQL Server (Currently selected: mysql-5.7), MySQL Tools & Connectors (Currently selected: Enabled), MySQL Preview Packages (Currently selected: Disabled), Ok
    mysql-apt-config    mysql-apt-config/select-product select  
    mysql-apt-config    mysql-apt-config/repo-codename  select  trusty
    mysql-apt-config    mysql-apt-config/unsupported-platform   select  abort
    # Choices: mysql-5.6, mysql-5.7, None
    mysql-apt-config    mysql-apt-config/select-server  select  

And the installation itself:

wget http://dev.mysql.com/get/mysql-apt-config_0.7.2-1_all.deb
sudo dpkg -i mysql-apt-config_0.7.2-1_all.deb

gets launched in interactive mode.

Any ideas?

Armo
  • 113
  • 1
  • 6
  • Checkout this post to see how to debug this and see what isn't working - https://stackoverflow.com/a/49136923/454421 - you probably have the wrong keys – Brett Allred Mar 06 '18 at 17:55

4 Answers4

24

This works for me if running as root

export DEBIAN_FRONTEND=noninteractive

debconf-set-selections <<< 'mysql-apt-config mysql-apt-config/repo-codename select trusty'
debconf-set-selections <<< 'mysql-apt-config mysql-apt-config/repo-distro select ubuntu'
debconf-set-selections <<< 'mysql-apt-config mysql-apt-config/repo-url string http://repo.mysql.com/apt/'
debconf-set-selections <<< 'mysql-apt-config mysql-apt-config/select-preview select '
debconf-set-selections <<< 'mysql-apt-config mysql-apt-config/select-product select Ok'
debconf-set-selections <<< 'mysql-apt-config mysql-apt-config/select-server select mysql-5.7'
debconf-set-selections <<< 'mysql-apt-config mysql-apt-config/select-tools select '
debconf-set-selections <<< 'mysql-apt-config mysql-apt-config/unsupported-platform select abort'

wget http://dev.mysql.com/get/mysql-apt-config_0.7.2-1_all.deb
dpkg -i mysql-apt-config_0.7.2-1_all.deb
apt-get update
apt-get install -y mysql-server-5.7
barbushin
  • 5,165
  • 5
  • 37
  • 43
  • This is not working for me with `mysql-apt-config_0.7.3-1_all.deb`. I still get the interactive prompt. Any ideas? – Stanley Aug 28 '16 at 16:06
  • 9
    Was able to get `mysql-apt-config_0.7.3-1_all.deb` working and wanted to post how I did it for others. Go through the interactive setup at least once and answer the questions. When done, run the following: `debconf-get-selections | grep mysql-apt-config`. This shows the necessary apt config settings; copy them and now place into your bash script. Run the `wget`, `dpkg`, and the `apt-get update`. For the `apt-get install` I had to use `mysql-server` instead of `mysql-server-5.7`. An easy way to find what package to install, is to run `sudo apt-cache search mysql | grep mysql`. Hope it helps! – Stanley Aug 28 '16 at 22:20
  • Thanks! This solved my problem... only needed 1 more line to trust the source: `sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 5072E1F5` – comjf Jul 11 '17 at 15:57
4

The accepted answer works. I simply want to put this links which gives some explanation about how to use debconf-set-selections and how to find the list of parameters.

Community
  • 1
  • 1
youssman
  • 1,514
  • 1
  • 17
  • 21
  • 1
    At least at the moment https://imsavva.com/silent-installation-mysql-5-7-on-ubuntu/ is down. – David Winiecki Mar 16 '23 at 05:33
  • @DavidWiniecki You can still travel back in time: https://web.archive.org/web/20220126180755/https://imsavva.com/silent-installation-mysql-5-7-on-ubuntu/ – mloskot Aug 05 '23 at 10:31
4

When running as non root user, exported variable(DEBIAN_FRONTEND) is not available with sudo. Making the variable part of dpkg command worked for me.

sudo DEBIAN_FRONTEND=noninteractive dpkg -i mysql-apt-config_0.7.2-1_all.deb
ranjeetcao
  • 1,743
  • 2
  • 20
  • 28
0

Simply run this. Works on 16.04

export DEBIAN_FRONTEND=noninteractive

debconf-set-selections <<< 'mysql-server-5.7 mysql-server/root_password password password'
debconf-set-selections <<< 'mysql-server-5.7 mysql-server/root_password_again password password'

apt-get install --assume-yes mysql-server-5.7 mysql-client

#update 'password' to whatever you want to use
mysql -u root -password -e "use mysql; UPDATE user SET authentication_string=PASSWORD('password') WHERE User='root'; flush privileges;"
rynop
  • 50,086
  • 26
  • 101
  • 112