I want a bash script that installs a MySQL 5.7 instance without needing any manual input.
I was following the tutorial on Digital Ocean and it says for 5.7 you have to run the following commands and then put commands into a prompt (screenshot below).
wget http://dev.mysql.com/get/mysql-apt-config_0.6.0-1_all.deb
sudo dpkg -i mysql-apt-config_0.6.0-1_all.deb
How can I automate the installation if it requires me to use a prompt? Should I try to simulate keystrokes? Or am I going about it the wrong way?
This answer is a combination and alteration of Bimmy's and khrm's answers.
STEP 1:
You have to set debconf
values which will automatically fill in the values prompted for by the installation.
export DEBIAN_FRONTEND="noninteractive"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password rootpw"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password rootpw"
To get the values you need, just run installation normally, a good tutorial of it is here
STEP 2:
Update the information needed for APT by adding the 5.7 repository and updating `apt-get
sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 5072E1F5
cat <<- EOF > /etc/apt/sources.list.d/mysql.list
deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7
EOF
sudo apt-get update
STEP 3:
Install MySQL. You can run my mysql_secure_installation
but then that will ask you for more prompts. mysql_secure_installation
is just a script so if you want to you can just run the parts of that script which are relevant to you.
I just ran
sudo apt-get install -y mysql-server-5.7
on its own.
You are proceeding in the wrong way. You don't need that package. That package only setup mysql repo.
You need to manually setup the mysql repository if you don't want prompt. Assuming you are using trusty (Ubuntu 14.04):
sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 5072E1F5
cat <<- EOF > /etc/apt/sources.list.d/mysql.list
deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7
EOF
sudo apt-get update
sudo apt-get install -y mysql-server-5.7
mysql_secure_installation
If you want other stuffs like workbench-6.2, etc. You need to include it like this in file /etc/apt/sources.list.d/mysql.list after the first entry:-
deb http://repo.mysql.com/apt/ubuntu/ trusty workbench-6.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With