18

How am I able to install MySQL 5.7 in the cloud on Amazon EC2?

Most of the Amazon Machine Instances (AMIs) that I see either lack any MySQL server or possess an older version such as MySQL Server 5.5

I want to use the latest and greatest.

Drew
  • 24,851
  • 10
  • 43
  • 78
  • 1
    What kind of OS are you using in the machine instances? Is it Linux or Windows? – buqing Aug 18 '16 at 18:53
  • @Robinson I am trying to capture some common ways that it can be achieved. So I chose RHEL 7 in my self-answer below. Sorry if it seems cheesy. Just wanted to share with people struggling for a solution. – Drew Aug 19 '16 at 00:21
  • You can remote to the server using ssh if it is linux, and then install application as what it is in a linux environment. If windows, you can also remote the server using "remote desktop connection" and install it as you are in a window system. Just make sure you open the proper port to login. – buqing Aug 19 '16 at 19:48
  • 1
    Off topic for Stackoverflow. How to install a specific version of mysql on a specific linux distro isn't a programming question – Vorsprung Sep 15 '16 at 08:34
  • @Vorsprung It is a community. I don't run it. Thanks for expressing yourself. By the way, you can close vote. You didn't :p – Drew Sep 15 '16 at 08:39
  • 1
    users can't close vote on a question with an open bounty, as I'm sure you know – Vorsprung Sep 15 '16 at 08:43
  • I know this. Programmers slave endlessly to get 5.7 working. And I attempted to share a solution. And yes I should know what you just said. I did not know a bounty was added to this and on that you are right @Vorsprung – Drew Sep 15 '16 at 08:44
  • the endlessly slaving programmers should use RDS then :) – Vorsprung Sep 15 '16 at 09:07
  • @Vorsprung RDS is awesome. Sometimes they need an instance. – Drew Sep 15 '16 at 09:08
  • 5
    @Vorsprung - [software tools commonly used by programmers](http://stackoverflow.com/help/on-topic) is directly mentioned as being on-topic. This is a grey area in my opinion, maybe this should have been on another site, maybe not. Either way there was a lot of effort put into the answer, sets a good example on how to answer questions and it makes the internet a better place. –  Sep 15 '16 at 15:30

3 Answers3

41

This is a relatively quick setup of MySQL 5.7.14 on Red Hat Enterprise Linux version 7 (RHEL7).

I am not affiliated with AWS; I just enjoy using their services.

Make sure you have an AWS EC2 account. Note that even though Amazon requires a creditcard on file, there will be no charges incurred for the first year if you adhere to their Free-tier terms. Typically this means a single micro-instance (1 Gb RAM) server running 24/7.

Launch of EC2 RHEL instance

Step 1: On AWS EC2 click "Launch Instance" and select "Red Hat Enterprise Linux 7.2 (HVM), SSD Volume Type - ami-775e4f16" as seen in the picture below. Note that the versions of the available or promoted AMIs (Amazon Machine Instance) will rotate over time and this is as of this writing. But the AMI number is shown above in the text.

enter image description here

Normally, I chose Amazon Linux AMI as my distro of choice. I don't do that anymore as it is their own hodge-podge and there is naturally uncertainty of which package manager to choose and therefore the files. So I stick with RHEL now.

On the "Choose an Instance Type" screen, select a free-tier eligible instance type as seen below:

enter image description here

Click Next. On the next Details screen click "Next" to accept defaults. On the storage screen change the size to 16GB and click "Next". Then "Next" again on Tag info. Next comes the "Configure Security Group" screen pictured below:

enter image description here

Accept the radio button of " create a new security group" for now. Note SSH port 22 is open to all (Anywhere) IP addresses with the 0.0.0.0/0 CIDR. Other options include detection of "My IP" (as in yours), or "Custom". Rest assured that with the next screen access will be locked down based on Security Keys we will setup. There is a button for Add Rule under the ports open to add such ports as MySQL 3306 or HTTP 80. But for now we will skip that. Note the security group name. Fill one in or accept the default for now. It is not critical to get this right as the security group can be changed later for a running Instance. Click Review and Launch.

Then click "Launch" (fear not, it is not going to Launch yet). As the next screen presents:

enter image description here

Note that as I already have some keypairs generated, it defaults to "Choose an existing keypair" in the first drop-down. Otherwise, you "Create a new key pair" with a given reminder name and proceed to "Download Key Pair". At this point you have the Key Pair as a .pem file. Treat that with the utmost of security, saving it to a place that you will not lose it. Preferably in a password protected area such as under your operating system User directory.

When you finally click "Launch Instances" on this same screen, the launch takes place in relation to that key pair (either just created or a pre-existing one). Note, the generation of a key pair might be a task you perform just once a year. Re-using a key pair again and again, up to you.

After you launch the instance, you have roughly five minutes before it comes live. Under the Instances left menu item, you know the instance is live when the Instance State reads "running" and the Status Checks reads "2/2 passed":

enter image description here

Remember the .pem file that you downloaded? Well just one time you need to create a .ppk file out of that for PuTTY, an SSH client program that will communicate cryto-secured to your running instance. For that we use the puttygen tool that works in harmony with PuTTY. So we run puttygen, load the .pem downloaded minutes before, and generate the .ppk file with a "Key passphrase" such as "I & love%ancHovies2_fjdi8Ha". Below is a picture of puttygen:

enter image description here

And the AWS EC2 page entitled Connecting to Your Linux Instance from Windows Using PuTTY. The steps are File / Load private key. Change the filter to All files (.). Find the .pem file. Hit "Open", then "Ok". Type in a Passphrase. Click "save private key", and save it in the same folder as a .ppk file alongside your .pem file. As mentioned, this is not something you might do but yearly.

Now run PuTTY, the SSH client. Use the Session / Host Name as something like

ec2-user@ec2-www-xxx-yyy-zzz.us-west-2.compute.amazonaws.com

So it is basically ec2-user@ concatenated with the Public DNS name that is seen under Instances on the EC2 Control panel. As for specifying the PuTTY .ppk file, it would look like the below, with the .ppk file chosen next to the Browse button:

enter image description here

Go back to the Session upper left hierarchy shown below, give this a profile name under Saved Sessions, and hit "Save". Hereafter when you load PuTTY, you merely load the session by name:

enter image description here

Don't forget that just about all you are doing here is saving the .ppk reference into a friendly named profile. And you may ocassionally need to change Host Name (certainly when you save an Instance image on EC2 and come back in with a new Instance IP address on a subsequent launch).

Ok, it is not easy. But it is what it is.

When you click Open it will attempt to connect to your RHEL instance. Hit Yes on the signature warning. Enter the prior saved .ppk Key Passphrase, and you should be sitting at a Linux prompt.

MySQL Installation (I will put these notes on GitHub)

enter image description here

enter image description here

enter image description here

URL01: Download MySQL Yum Repository

URL02: Chapter 1 Installing MySQL on Linux Using the MySQL Yum Repository

You now have MySQL 5.7.14 loaded and running on EC2 with a database and user setup. Your servers need to be imaged. See this answer here of mine for creating images (AMI's). Backup your data. See the EC2 documentation such as Best Practices for Amazon EC2.

Back to security: best practices certainly suggest not opening up your db to direct connects through Security Groups for port 3306. How you choose to adhere to that is your choice, such as with a PHP, Java, or other programming API. Note that various db client programs can connect through SSH tunnels such as MySQL Workbench. In addition various development libraries exist with SSH Tunnels but they are not terribly easy to develop against (mainly due to difficult key chains and lack of extensive developer experiences). For instance, there is one for C# here.

In addition AWS has RDS and other database offering for less hands-on and rolling your own like the above. The reason many developers target EC2 is due to the fact that you have a full blown server for your other programming initiatives.

If you do modify the Security Groups as mentioned before, please consider using IP Ranges based on CIDR entries and use caution before over-exposing your datastores. Or over granting. Much the same best practices as you would for on-premise work.

Concerning this MySQL section, my GitHub notes for the above few pictures are located Here.

Community
  • 1
  • 1
Drew
  • 24,851
  • 10
  • 43
  • 78
  • Following your steps using Amazon Linux AMI, didn't work... I think there must be additional configuration to do that... – georgeos Aug 14 '17 at 04:59
  • (((on this step yum install mysql-community-server))) ....................................................i am getting error Error: Package: mysql-community-server-5.7.19-1.el7.x86_64 (mysql57-community) Requires: libsasl2.so.3()(64bit) Error: Package: mysql-community-server-5.7.19-1.el7.x86_64 (mysql57-community) Requires: systemd You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest – M.Shuaib Imran Aug 20 '17 at 13:56
  • 1
    I didn't follow your answer, but had to upvote. What a wonderful way of guiding someone. It is an article on its own rather than a post. Thanks :) – Graph Sep 14 '17 at 00:38
  • 2
    For anyone who has trouble differentiating 1's and l's like me, the repository is `wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm` – Jon McClung Dec 04 '18 at 17:47
20

I had the same issue, but i didn’t want to use Red Hat or any other OS than Amazon Linux AMI. So, here is the process to install MySQL 5.7 and upgrade an older version.

Short path (without screenshots)

wget https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
yum localinstall mysql57-community-release-el6-11.noarch.rpm
yum remove mysql55 mysql55-common mysql55-libs mysql55-server
yum install mysql-community-server
service mysqld restart
mysql_upgrade -p

Long path (with screenshots)

First of all, just to validate you can check the current version. enter image description here

Then, you should download the repo for EL6 11

wget https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm

enter image description here

Next, make a localinstall:

yum localinstall mysql57-community-release-el6-11.noarch.rpm

enter image description here

This is probably the key for a successful installation. You should remove the previous packages, regarding to MySQL 5.5

yum remove mysql55 mysql55-common mysql55-libs mysql55-server

enter image description here

Finally, you can install MySQL 5.7

yum install mysql-community-server

enter image description here

Restart the MySQL Server and upgrade your database

service mysqld restart
mysql_upgrade -p

enter image description here

You can validate you installation by authenticating to MySQL

enter image description here

georgeos
  • 2,351
  • 2
  • 24
  • 28
  • 4
    (((on this step yum install mysql-community-server))) ....................................................i am getting error Error: Package: mysql-community-server-5.7.19-1.el7.x86_64 (mysql57-community) Requires: libsasl2.so.3()(64bit) Error: Package: mysql-community-server-5.7.19-1.el7.x86_64 (mysql57-community) Requires: systemd You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest. – M.Shuaib Imran Aug 20 '17 at 13:54
  • @M.ShuaibImran You are using the wrong package. Check my post: mysql57-community-release-el6-11.noarch.rpm – georgeos Aug 21 '17 at 03:04
  • I have to remove everything from MYSQL? I tried running your command, but it does not work on my Centos 6. # rpm -qa | grep mysql mysql57-community-release-el6-11.noarch compat-mysql51-5.1.73-1.el6.remi.x86_64 mysql-libs-5.5.57-1.el6.remi.x86_64 php55w-mysql-5.5.38-1.w6.x86_64 – Renato Lazaro Sep 04 '17 at 17:26
  • @RenatoLazaro it's because there are some differences between Amazon Linux AMI and CentOs, you can check them here: https://forums.aws.amazon.com/thread.jspa?threadID=146805 . Can you try instead this package: mysql57-community-release-el7-11.noarch.rpm and follow the same procedure as I posted. – georgeos Sep 04 '17 at 21:28
  • I was able to do the installation by using (localhost mysql57-community-release-el6-11.noarch.rpm). But upon restart (service mysqld restart) the MYSQL server does not start. (Failed) know how to solve? – Renato Lazaro Sep 05 '17 at 13:49
  • @RenatoLazaro check /var/log/mysqld.log Also https://stackoverflow.com/questions/5441972/how-to-see-log-files-in-mysql – georgeos Sep 07 '17 at 12:35
1

sudo yum install mysql57-server

Elijah Lynn
  • 12,272
  • 10
  • 61
  • 91
  • `Error: mysql57-server conflicts with mysql55-server-5.5.62-1.23.amzn1.x86_64` – retrovertigo Oct 24 '19 at 22:55
  • You have to remove first, try `sudo yum remove mysql-server`, it might be a variation and could be `mysql55-server`. That also could not work and an easy route is to start with a server that never had it installed to begin with, which was my situation. – Elijah Lynn Oct 24 '19 at 23:56