How to install Percona MySQL 5.6 on Ubuntu 14.04 LTS from a script (i.e. without an interactive prompt for the mysql root password)

By Adrian Smith14 May 2015200 words1 mins to read

Ubuntu 14.04 (and various versions of Debian) come with MySQL 5.5. If you need MySQL 5.6 features (such as better join algorithms) you can install the Percona software, as described here.

However, the installation process prompts you for the database's root password. This isn't convenient if you're running the installation process from a script e.g. a Vagrant or Docker initialization script. Here's the whole script to install Percona 5.6 and to set the root password to "root" without a prompt:

sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
sudo bash -c 'echo deb http://repo.percona.com/apt trusty main >> /etc/apt/sources.list'
sudo bash -c 'echo deb-src http://repo.percona.com/apt trusty main >> /etc/apt/sources.list'
sudo apt-get update
echo "percona-server-server-5.6 percona-server-server/root_password password root" | sudo debconf-set-selections
echo "percona-server-server-5.6 percona-server-server/root_password_again password root" | sudo debconf-set-selections
sudo apt-get install -qq -y percona-server-server-5.6 percona-server-client-5.6

I got to this by finding out what keys exist in debconf uses as follows (after having installed mysql and entering the password interactively):

sudo debconf-show --listowners
sudo debconf-show percona-server-server-5.6

This article was written by Adrian Smith on 14 May 2015

Follow me: Facebook | Twitter | LinkedIn | Email

More on: MySQL | Linux & UNIX