5

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?

enter image description here

2
  • @tt_Gantz Ignore the downvote. And follow what I have given. You don't need that package Commented Jun 14, 2016 at 8:11
  • I have given answer from what that package does. Commented Jun 14, 2016 at 12:23

3 Answers 3

11

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.

Sign up to request clarification or add additional context in comments.

1 Comment

congrats, it was a pleasure to help you.
3

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

12 Comments

@GeraldSchneider His main problem is installing mysql-server. Not prompt. He is getting prompt because that package setup repo. So remove the neg vote.
Firstly, calm down. There are people who don't use this site 24/7, so there is no need to become personal when you don't get an answer immedietly. The question, as I see it, asks "How can I automatically answer prompts during the installation of a package?". Your answer doesn't address this issue, it is only helpful for this specific case with this specific package. That's why you got a downvote for me. On SO we try to accumulate questions and answers in a way that help other people who have the same or similar problems.
The chances that your answer will help anyone else are quite slim. The second answer that has been posted in the meantime however directly addresses the actual question (as I see it), can be easily adapted for other packages and works on every debian based distribution. Hence it got an upvote from me. You may have noticed that the OP hasn't reacted to any suggestion yet. As long as the OP doesn't clarify in any way that your solution was helpful I don't see any reason to retract my vote.
I don't mind how it happens as long as it can done through a bash script which is why I mentioned "Or am I going about it the wrong way?" at the end of the questions. This answer still needed a password to be entered into the prompt. However combined with @BimmyAndJimmy 's answer for configuring the password I was able to get it to work
It's getting that key from pgp.mit.edu. I got this from here: dev.mysql.com/doc/mysql-apt-repo-quick-guide/en That package does it on it's own.
|
2

I think this link may be useful for you. The video shows the whole process using a previous version (5.6).

To sum up, you should:

  1. Export a variable called DEBIAN_FRONTEND with the value "noninteractive".
  2. Use debconf-set-selections in order to set a root password (for your MySQL Server).
  3. Install mysql-server-5.7 package.
  4. Run a secure installation afterwards.

    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"
    sudo apt-get install -y mysql-server-5.7
    mysql_secure_installation
    

NOTE: You can install debconf-utils typing the following command: sudo apt-get install -y debconf-utils

3 Comments

This answer is wrong on many counts. First what if user needs mysql 5.8 morrow? It won't be in distro repo. And currently in trusty repo, mysql5.7 isn't there.
After running all the commands I get an error saying it's unable to find mysql-server-5.7
It's because, you won't find mysql-server-5.7 in the distro repo. You have to enable mysql repo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.