MySQL Client installation on Amazon Linux EC2

0

I am in the process of setting up a dev environment wherein I am trying to set up connectivity between an amazon linux ec2 instance (in a private subnet) and a MYSQL RDS deployment endpoint (in it's own dedicated private DB subnet). While testing the connectivity I am trying to install a MYSQL client on my ec2 instances using the standard yum package installer. In the UserData configuration of my EC2 instances, I have just added the following basic installation commands.

echo "Installing MySQL client"
yum -y install mysql

Further inspection of the EC2 instance's system logs indicates that the MYSQL client has been installed successfully. (Or at least appears to be) However when I SSH into the instance and run a simple mysql command, I get the following error.

*[ec2-user@ip-172-31-0-176 ~]$ mysql
-bash: mysql: command not found*

Snippet of Systems Logs

Installing MySQL Packages
Loaded plugins: priorities, update-motd, upgrade-helper
Existing lock /var/run/yum.pid: another copy is running as pid 2089.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  78 M RSS (325 MB VSZ)
    Started: Tue Jun  7 14:01:48 2022 - 00:01 ago
    State  : Running, pid: 2089
Resolving Dependencies
--> Running transaction check
---> Package mysql55.x86_64 0:5.5.62-1.23.amzn1 will be installed
--> Processing Dependency: real-mysql55-libs(x86-64) = 5.5.62-1.23.amzn1 for package: mysql55-5.5.62-1.23.amzn1.x86_64
--> Processing Dependency: mysql-config for package: mysql55-5.5.62-1.23.amzn1.x86_64
--> Running transaction check
---> Package mysql-config.x86_64 0:5.5.62-1.23.amzn1 will be installed
---> Package mysql55-libs.x86_64 0:5.5.62-1.23.amzn1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
 Package           Arch        Version                  Repository         Size
================================================================================
Installing:
 mysql55           x86_64      5.5.62-1.23.amzn1        amzn-updates      7.5 M
Installing for dependencies:
 mysql-config      x86_64      5.5.62-1.23.amzn1        amzn-updates       49 k
 mysql55-libs      x86_64      5.5.62-1.23.amzn1        amzn-updates      816 k
Transaction Summary
================================================================================
Install  1 Package (+2 Dependent packages)
Total download size: 8.3 M
Installed size: 31 M
Downloading packages:
--------------------------------------------------------------------------------
Total                                               34 MB/s | 8.3 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql55-libs-5.5.62-1.23.amzn1.x86_64                        1/3 
  Installing : mysql-config-5.5.62-1.23.amzn1.x86_64                        2/3 
  Installing : mysql55-5.5.62-1.23.amzn1.x86_64                             3/3 
  Verifying  : mysql-config-5.5.62-1.23.amzn1.x86_64                        1/3 
  Verifying  : mysql55-libs-5.5.62-1.23.amzn1.x86_64                        2/3 
  Verifying  : mysql55-5.5.62-1.23.amzn1.x86_64                             3/3 
Installed:
  mysql55.x86_64 0:5.5.62-1.23.amzn1                                            
Dependency Installed:
  mysql-config.x86_64 0:5.5.62-1.23.amzn1                                       
  mysql55-libs.x86_64 0:5.5.62-1.23.amzn1                                       
Complete!

Any recommendations on how to proceed with resolving this issue ?

  • Maybe add sudo? Or are you root user?

  • Can you check if you can run it via the absolute path? Try to execute /usr/bin/mysql It would be interesting if is not installed or just not in the command cache. You can also try to find traces of the files via find / -name "mysql"

  • I tried executing the 'find' command earlier, but was unable to locate mysql anywhere on local EC2 instance. When I explicitly executed "yum install mysql" after the instance itself is available (via SSH login), the mysql client was installed successfully and I was able to connect to the RDS endpoint. When I compared the output of the 2 install command executions (userData vs explicit install), I noticed there was a difference in the "Downloading packages:" section of the output. With explicit install, the section included a list of 3 dependent packages. Not entirely sure if that will make any difference though.

    BTW : Switching to Amazon Linux 2 from Amazon-Linux seems to have magically solved the problem. But still would like to know exactly what's happening here.

  • Can you post the AMI id for AL2 that you used? I noticed in my test that the current public AMI ships with mariadb and yum install mysql will install the mariadb package.

  • AMI ID : ami-0ca285d4c2cda3300

    Snippet from instance log : [ 25.946073] cloud-init[2515]: Installing MySQL client [ 26.603569] cloud-init[2515]: Loaded plugins: extras_suggestions, langpacks, priorities, update-motd [ 26.820267] cloud-init[2515]: Resolving Dependencies [ 26.821843] cloud-init[2515]: --> Running transaction check [ 26.822893] cloud-init[2515]: ---> Package mariadb.x86_64 1:5.5.68-1.amzn2 will be installed [ 27.034973] cloud-init[2515]: --> Finished Dependency Resolution [ 27.094845] cloud-init[2515]: Dependencies Resolved [ 27.096335] cloud-init[2515]: ================================================================================ [ 27.098077] cloud-init[2515]: Package Arch Version Repository Size [ 27.099817] cloud-init[2515]: ================================================================================ [ 27.100100] cloud-init[2515]: Installing: [ 27.100358] cloud-init[2515]: mariadb x86_64 1:5.5.68-1.amzn2 amzn2-core 8.8 M [ 27.100593] cloud-init[2515]: Transaction Summary [ 27.100811] cloud-init[2515]: ================================================================================ [ 27.106380] cloud-init[2515]: Install 1 Package [ 27.106567] cloud-init[2515]: Total download size: 8.8 M [ 27.106714] cloud-init[2515]: Installed size: 49 M

4 Answers
1

Hi MandarBk,

Going through the forum correspondences, I see that you’re trying to install mysql via user-script on Amazon Linux 1 AMI, but you’re not finding the package inside the operating system upon launch of the instance. Nonetheless, the same steps are working fine for your Amazon Linux 2 AMI “ami-0ca285d4c2cda3300”.

Since the initial Amazon Linux 1 AMI Id was not mentioned in the correspondences, I’ve tried to use another Amazon Linux 1 AMI “ami-0021005f0cbcd6aaa” which is available in the us-west-2 region for replicating this issue. The user data script I’ve used is as follows:

#!/bin/bash
set -x
echo "Installing MySQL client"
yum -y install mysql
yum list installed mysql
rpm -qa | grep mysql

It executed successfully upon instance launch, without any issues, as can be seen in the output below:

Starting cloud-init: Cloud-init v. 0.7.6 running 'modules:final' at Wed, 08 Jun 2022 18:59:35 +0000. Up 19.62 seconds.
+ echo 'Installing MySQL client'
Installing MySQL client

+ yum -y install mysql
Loaded plugins: priorities, update-motd, upgrade-helper
Existing lock /var/run/yum.pid: another copy is running as pid 2646.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory : 126 M RSS (373 MB VSZ)
    Started: Wed Jun  8 18:59:32 2022 - 00:04 ago
    State  : Running, pid: 2646
Resolving Dependencies
--> Running transaction check
---> Package mysql.noarch 0:5.5-1.6.amzn1 will be installed
--> Processing Dependency: mysql55 >= 5.5 for package: mysql-5.5-1.6.amzn1.noarch
--> Running transaction check
---> Package mysql55.x86_64 0:5.5.62-1.23.amzn1 will be installed
--> Processing Dependency: real-mysql55-libs(x86-64) = 5.5.62-1.23.amzn1 for package: mysql55-5.5.62-1.23.amzn1.x86_64
--> Processing Dependency: mysql-config for package: mysql55-5.5.62-1.23.amzn1.x86_64
--> Running transaction check
---> Package mysql-config.x86_64 0:5.5.62-1.23.amzn1 will be installed
---> Package mysql55-libs.x86_64 0:5.5.62-1.23.amzn1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
 Package           Arch        Version                  Repository         Size
================================================================================
Installing:
 mysql             noarch      5.5-1.6.amzn1            amzn-main         2.7 k
Installing for dependencies:
 mysql-config      x86_64      5.5.62-1.23.amzn1        amzn-updates       49 k
 mysql55           x86_64      5.5.62-1.23.amzn1        amzn-updates      7.5 M
 mysql55-libs      x86_64      5.5.62-1.23.amzn1        amzn-updates      816 k
Transaction Summary
================================================================================
Install  1 Package (+3 Dependent packages)
Total download size: 8.3 M
Installed size: 31 M
Downloading packages:
--------------------------------------------------------------------------------
Total                                               27 MB/s | 8.3 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql55-libs-5.5.62-1.23.amzn1.x86_64                        1/4 
  Installing : mysql-config-5.5.62-1.23.amzn1.x86_64                        2/4 
  Installing : mysql55-5.5.62-1.23.amzn1.x86_64                             3/4 
  Installing : mysql-5.5-1.6.amzn1.noarch                                   4/4 
  Verifying  : mysql-5.5-1.6.amzn1.noarch                                   1/4 
  Verifying  : mysql-config-5.5.62-1.23.amzn1.x86_64                        2/4 
  Verifying  : mysql55-libs-5.5.62-1.23.amzn1.x86_64                        3/4 
  Verifying  : mysql55-5.5.62-1.23.amzn1.x86_64                             4/4 
Installed:
  mysql.noarch 0:5.5-1.6.amzn1                                                  
Dependency Installed:
  mysql-config.x86_64 0:5.5.62-1.23.amzn1   mysql55.x86_64 0:5.5.62-1.23.amzn1  
  mysql55-libs.x86_64 0:5.5.62-1.23.amzn1  
Complete!

+ yum list installed mysql
Loaded plugins: priorities, update-motd, upgrade-helper
Existing lock /var/run/yum.pid: another copy is running as pid 2808.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  44 M RSS (292 MB VSZ)
    Started: Wed Jun  8 18:59:38 2022 - 00:01 ago
    State  : Running, pid: 2808
Installed Packages
mysql.noarch                      5.5-1.6.amzn1                       @amzn-main

+ grep mysql
+ rpm -qa
mysql-5.5-1.6.amzn1.noarch
mysql55-libs-5.5.62-1.23.amzn1.x86_64
mysql55-5.5.62-1.23.amzn1.x86_64
mysql-config-5.5.62-1.23.amzn1.x86_64

When I login into my instance via ssh, I am also able to confirm that mysql has been installed successfully. Please see the output of the below commands:

[ec2-user@ip-172-31-2-176 ~]$ sudo rpm -qa | egrep "mysql|mariadb"
mysql-5.5-1.6.amzn1.noarch
mysql55-libs-5.5.62-1.23.amzn1.x86_64
mysql55-5.5.62-1.23.amzn1.x86_64
mysql-config-5.5.62-1.23.amzn1.x86_64
[ec2-user@ip-172-31-2-176 ~]$ yum list installed mysql
Failed to set locale, defaulting to C
Loaded plugins: priorities, update-motd, upgrade-helper
Installed Packages
mysql.noarch                         5.5-1.6.amzn1                         @amzn-main

I'm willing to replicate and troubleshoot your issue further on my side, henceforth I’d like for you to share the AMI Id that you used initially and had faced issues with.

Looking forward to hearing from you soon!

Cebi
answered 2 years ago
  • Hi, Thanks for looking into this. I have just switched the setup back to amazon linux 1 and indeed I can see things working now. I did not use any hardcoded ami id and was using the terraform script to setup the infra.

    data "aws_ami" "amazon_linux" {
      most_recent = true
      owners      = ["amazon"]
    
      filter {
        name = "name"
        values = [
          "amzn-ami-hvm-*-x86_64-gp2",
        ]
      }
    
      filter {
        name = "owner-alias"
        values = [
          "amazon",
        ]
      }
    }
    

    Anyways thank you very much for your time and efforts. Thanks for the "yum list installed mysql" command.

0

It is still NOT working with Amazon Linux 2023 (AMI id: ami-06ca3ca175f37dd66)

cloud-init-output.log

  • echo 'Installing MySQL client' Installing MySQL client
  • yum -y install mysql Amazon Linux 2023 repository 23 MB/s | 15 MB 00:00
    Amazon Linux 2023 Kernel Livepatch repository 481 kB/s | 158 kB 00:00
    No match for argument: mysql Error: Unable to find a match: mysql
  • yum list installed mysql Error: No matching Packages to list
  • rpm -qa
  • grep mysql 2023-07-16 11:05:17,369 - cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts) 2023-07-16 11:05:17,370 - util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python3.9/site-packages/cloudinit/config/cc_scripts_user.py'>) failed

UPDATE: seems to work by user data, but I dont know what I am doing (mariadb, dnf)

#!/bin/bash
sudo dnf update -y
sudo dnf install -y mariadb105-server
syr
answered 8 months ago
0

I am running into problems installing mysql:

[root@ip-10-0-0-14 ~]# yum install mysql
Last metadata expiration check: 0:48:27 ago on Wed Jul 19 18:54:29 2023.
No match for argument: mysql
Error: Unable to find a match: mysql

My AMI ID is ami-0272362388eae3591

OS info:

NAME="Amazon Linux"
VERSION="2023"
ID="amzn"
ID_LIKE="fedora"
VERSION_ID="2023"
PLATFORM_ID="platform:al2023"
PRETTY_NAME="Amazon Linux 2023"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023"
HOME_URL="https://aws.amazon.com/linux/"
BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023"
SUPPORT_END="2028-03-01"
AQM
answered 8 months ago
0

Hello All,

You can check the codes below.

For Amazon Linux 2:

rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-9.noarch.rpm && yum -y install mysql-community-server

For Amazon Linux 2023:

rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm && dnf -y install mysql-community-server
profile picture
answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions