amazon-web-servicesamazon-ec2aws-codebuild

Unable to install mysql on Amazon Linux 2023


I'm trying to run the following command in my buildspec.yaml (on AWS Codebuild) to insert my React App's source version into MySQL during the build.

- echo "Saving value to MySQL RDS"
- mysql -h $DB_HOST -u $DB_USER -p $DB_PASSWORD -D $DB_NAME -e "INSERT INTO versionReact (version) VALUES ('$REACT_APP_VERSION');"

When I do so, I get the following error:

/codebuild/output/tmp/script.sh: line 4: mysql: command not found

This intrinsically makes sense, why would the Amazon EC2 box running codebuild have MySQL on it. I found this great SO article that makes life look easy if you're running Amazon Linux 2, because there's already an available MySQL package on that runtime.

However, I'm running Amazon Linux 2023 to support Node 18. The details for installing MySQL onto Amazon Linux 2023 appear to be more complex as one needs to retrieve the noarch.rpm file from MySQL community downloads first.

I tried running the following:

- wget https://repo.mysql.com//mysql80-community-release-el9-3.noarch.rpm
- sudo ls
- sudo yum install mysql80-community-release-el9-1.noarch.rpm

I can see the noarch.rpm file in the directory: enter image description here

But it fails to run the yum install with "Can not load RPM file: mysql80-community-release-el9-1.noarch.rpm"

Looking for some support on how I might get unstuck (and accomplish my base objective of running that mysql CLI command to insert into my table)?


Solution

  • Please refer to the AWS docs: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.CreatingConnecting.MySQL.html#CHAP_GettingStarted.Connecting.MySQL

    # install
    sudo dnf update -y
    sudo dnf install mariadb105
    
    # connect to instance
    mysql -h endpoint -P 3306 -u admin -p
    

    Don't forget to ensure that your network setup allows you to reach the RDS instance on the desired port.