我正在用户数据中使用以下命令通过 Cloudformation 在我的 EC2 实例中安装 MySQL 客户端:
- yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
- yum install -y mysql-community-client.x86_64
但是登录EC2后,我发现无法执行某些命令,例如
mysqldump
mysql
查看/usr/bin,发现mysql、mysqldump、mysqlcheck等mysql相关命令都没有。
最后检查了EC2服务器的系统日志和cloud-init日志,发现如下日志:
[ 75.069708] cloud-init[2691]: Installing:
[ 75.071941] cloud-init[2691]: mysql-community-client x86_64 8.0.28-1.el7 mysql80-community 53 M
[ 75.076458] cloud-init[2691]: mysql-community-libs x86_64 8.0.28-1.el7 mysql80-community 4.7 M
[ 75.096330] cloud-init[2691]: replacing mariadb-libs.x86_64 1:5.5.68-1.amzn2
[ 75.099727] cloud-init[2691]: mysql-community-libs-compat x86_64 8.0.28-1.el7 mysql80-community 1.2 M
[ 75.104188] cloud-init[2691]: replacing mariadb-libs.x86_64 1:5.5.68-1.amzn2
[ 75.107629] cloud-init[2691]: Installing for dependencies:
[ 75.110473] cloud-init[2691]: mysql-community-client-plugins x86_64 8.0.28-1.el7 mysql80-community 5.7 M
[ 75.116311] cloud-init[2691]: mysql-community-common x86_64 8.0.28-1.el7 mysql80-community 630 k
[ 75.116510] cloud-init[2691]: ncurses-compat-libs x86_64 6.0-8.20170212.amzn2.1.3
[ 75.116976] cloud-init[2691]: amzn2-core 308 k
[ 75.117416] cloud-init[2691]: Transaction Summary
[ 75.117888] cloud-init[2691]: ================================================================================
[ 75.118345] cloud-init[2691]: Install 3 Packages (+3 Dependent packages)
[ 75.118801] cloud-init[2691]: Total download size: 65 M
[ 75.119227] cloud-init[2691]: Downloading packages:
[ 75.393593] cloud-init[2691]: warning: /var/cache/yum/x86_64/2/mysql80-community/packages/mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
[ 75.399647] cloud-init[2691]: Public key for mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm is not installed
[ 76.034754] cloud-init[2691]: --------------------------------------------------------------------------------
[ 76.039388] cloud-init[2691]: Total 67 MB/s | 65 MB 00:00
[ 76.043679] cloud-init[2691]: Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[ 76.075984] cloud-init[2691]: Importing GPG key 0x5072E1F5:
[ 76.078955] cloud-init[2691]: Userid : "MySQL Release Engineering <[email protected]>"
[ 76.082649] cloud-init[2691]: Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
[ 76.085875] cloud-init[2691]: Package : mysql80-community-release-el7-1.noarch (installed)
[ 76.089472] cloud-init[2691]: From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[ 76.093229] cloud-init[2691]: Public key for mysql-community-client-8.0.28-1.el7.x86_64.rpm is not installed
[ 76.097724] cloud-init[2691]: Failing package is: mysql-community-client-8.0.28-1.el7.x86_64
[ 76.101487] cloud-init[2691]: GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
如何解决这个问题?请推荐。
更新: 实例是:Amazon Linux 2
Fn::Base64: !Sub |
#cloud-config
repo_update: true
write_files:
- content: |
REGION=${Region}
ENV=${Env}
path: /etc/environment
append: true
- content: "${EFSFileSystem}:/ /efs efs defaults,_netdev 0 0"
path: /etc/fstab
append: true
packages:
- amazon-efs-utils
- jq
- nfs-utils
- ruby
- unzip
- wget
package_update: true
package_upgrade: true
runcmd:
- [ mkdir, /efs ]
- [ mount, /efs ]
- [ sh, -c, "amazon-linux-extras install -y nginx1.12 php7.4" ]
- yum install -y php-opcache php-gd php-mbstring php-pecl-zip php-xml
- yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
- yum install -y mysql-community-client.x86_64
- wget -q https://s3.amazonaws.com/amazoncloudwatch-agent/linux/amd64/latest/AmazonCloudWatchAgent.zip -O /tmp/AmazonCloudWatchAgent.zip
- unzip -d /tmp/AmazonCloudWatchAgentInstaller /tmp/AmazonCloudWatchAgent.zip
- rpm -ivh /tmp/AmazonCloudWatchAgentInstaller/amazon-cloudwatch-agent.rpm
- /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${CloudwatchConfigSsm} -s
- wget -q https://aws-codedeploy-ap-northeast-1.s3.ap-northeast-1.amazonaws.com/latest/install -O /tmp/aws-codedeploy-install.rb
- [ ruby, /tmp/aws-codedeploy-install.rb, auto ]
- systemctl enable nginx
- service codedeploy-agent start
这个问题确实困扰了我,我不得不上网搜索更多细节。请记住始终使用 yum Amazon Linux,下面的代码应该安装 MySQL CLI
sudo yum update
sudo yum install mysql –y
正常的安装代码对我不起作用,所以我看到此代码来获取我使用的社区版本。
sudo yum install -y https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
sudo yum install -y mysql-community-client
sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
sudo yum install mysql-community-client.x86_64
这为我完成了工作,运行 mysql 现在你应该看到响应,连接到 mysql 数据库使用
mysql -h YOUR-DB-CONNECTION-STRING -P 3306 -u admin -p
这对我来说效果很好,就像你在像我一样尝试更直接的安装时出错一样。我从下面链接的一篇文章中得到了这个方法,以防您想查看更多信息
https://www.digitalspeed.online/all-articles/how-to-install-mysql-cli-on-your-aws-ec2-instance/