【AWS・EC2】bundle exec rake db:migrate RAILSENV=production 오류 Could not find gem'mySql 2'in and of the gem sources listed in your Gemufile해결책

4612 단어 AWS

컨디션


AWS 내부: rails6
로컬 환경: rails6

하고 싶은 일


aws의 EC2에 연결된 상태에서 bundle exec rake db:migrate RAILS나 ENV 하고 싶어.

오류 발생


EC2에서 bundle exec rake db:migrate RAILSENV = production 에서 다음 오류가 표시됩니다.
Could not find gem 'mysql2' in any of the gem sources listed in your Gemfile.

오류가 발생한 경과


· 공식 환경을 AWS의 EC2로 설계했을 때의 오류
• 아래 기사를 보면서 투자조합을 공식적인 환경으로 설계한다.
https://qiita.com/Yuki_Nagaoka/items/dbb185feb6d4f051c2f2#2mysql%E3%81%AE%E7%92%B0%E5%A2%83%E5%A4%89%E6%95%B0%E3%81%AE%E8%A8%AD%E5%AE%9A
https://qiita.com/naoki_mochizuki/items/5a1757d222806cbe0cd1#mysql%E3%81%AE%E8%A8%AD%E5%AE%9A
・ 테스트 환경, 개발 환경, 공식 환경을 모두 Posgresql로 구현하고자 하였으나, EC2를 사용하여 디버깅하는 방법을 소개한 글에는 Mysql이 많아 중도에 Mysql로 변경된 경위가 있다.

원인·고찰


EC2의 응용 프로그램gemfile에 mysql2가 없습니까?
권한이 없습니까?
EC2와 로컬 환경이 다릅니까?

시도해 본 일

vi Gemfile에서 Gemfile을 확인합니다.
→ mysql이 추가되었습니다.(참조 이미지)

EC2 응용 프로그램(조합)에서 brew install mysol을 실행합니다.


다음과 같이 표시됩니다.
[shogo@ip-10-0-0-58 Portfolio]$ brew install mysql
bash: brew: コマンドが見つかりません

터미널에서 다음 내용을 테스트합니다.

$  bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"
$ bundle install  https://qiita.com/sun_peace/items/f06cc95e63a71b7296ec
→ 다음 오류를 표시합니다.
To see why this extension failed to compile, please check the mkmf.log which can be found here:

 /home/shogo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/mysql2-0.5.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/shogo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3 for inspection.
Results logged to /home/shogo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/mysql2-0.5.3/gem_make.out

An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
 mysql2
[shogo@ip-10-0-0-58 Portfolio]$
→ 로그 조회 오류지만 파일 중 하나를 모른다.

psax|grep mysql에서 mysql가 작동하는지 관찰하면 다음과 같습니다.

[shogo@ip-10-0-0-58 Portfolio]$ ps ax | grep mysql 
 5032 pts/0  S+   0:00 grep --color=auto mysql
29854 ?    Sl   0:04 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
[shogo@ip-10-0-0-58 Portfolio]$
→ 잠시 가동됐나요?

mysql2를 EC2로 테스트하면 bundle install이 수행되지 않습니다.

ln /home/linuxbrew/.linuxbrew/bin/gcc-7 /home/linuxbrew/.linuxbrew/bin/gcc 이후에는 다음과 같이 표시됩니다.
[shogo@ip-10-0-0-58 Portfolio]$ ln /home/linuxbrew/.linuxbrew/bin/gcc-7 /home/linuxbrew/.linuxbrew/bin/gcc
ln: failed to access `/home/linuxbrew/.linuxbrew/bin/gcc-7': No such file or directory
[shogo@ip-10-0-0-58 Portfolio]$

터미널에 다음 내용을 입력하십시오.

&  bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
아래와 같다.
To see why this extension failed to compile, please check the mkmf.log which can be found here:

 /home/shogo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/mysql2-0.5.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/shogo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3 for inspection.
Results logged to /home/shogo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/mysql2-0.5.3/gem_make.out

An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
 mysql2
[shogo@ip-10-0-0-58 Portfolio]$

해결책

sudo yum install mysql-devel
잘못된 문장 위에 쓰여 있다.
이 잘못에 주의하면 몇 가지 해결 방법이 있다.

좋은 웹페이지 즐겨찾기