Automated installation of MySQL 5.7 community server on Amazon EC2 instances with Amazon Linux AMI

Sudip Raval
Aubergine Solutions
2 min readAug 16, 2017

Update

MySQL server with version 5.7 is now available in Amazon Linux yum repo list. You can easily install it with command:

yum install mysql57-server

You can read the post if you want to know how I installed mysql community server from binary package and automated the password change with the help of expect program when mysql57-server was not available in yum repo on Amazon Linux!

Original Post

Couple of days ago, we upgraded our MySQL server to version 5.7 in development. So we need to give the support of MySQL server installation in our build system’s program which manages sandboxes (EC2 instances with Amazon Linux AMI image) for build and testing purposes on AWS.

Well, as of now, writing this, Amazon Linux AMI’s yum package manager doesn’t have mysql with version 5.7 in their repository list. So, we have to choose the option to install MySQL from distribution source package in next step after creating sandbox on Amazon AWS.

To create sandbox, we’re using AWS Command Line Interface as follows:

aws ec2 run-instances --image-id {IMAGE_ID} --count 1 --instance-type {INSTANCE_TYPE} --key-name {KEY_PAIR_NAME} --security-groups {SECURITY_GROUP} --profile {PROFILE} --user-data mysql57_yum.sh >> out.json

You may find other APIs for fuzzy auto-completion for ec2 here such as to know the status, to create/start/stop/terminate ec2 instances.

This is the bash script (mysql57_yum.sh) which installs MySQL 5.7 community server on Amazon Linux AMI type machine.

Thanks to expect program and this gist, which helped me to figure out how to interact with MySQL dialogues.

If you just want to install MySQL community server 5.7 simply on your server which supports yum package manager then just save above gist as mysql57_yum.sh and just run it as root user.

Checkout from here, for how many linux distributions, MySQL is supported.

Note: If mysql community server 5.7 is available in yum repo list, then it is highly recommended that you install it directly from there.

I hope sharing this would help others to install MySQL automatically using above script.

--

--