Docker Rails mysql 未连接

4 mysql ruby-on-rails docker docker-compose

我正在尝试将主机上的 Rails 应用程序连接到 docker mysql 映像。但我收到此错误:

 Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/Cellar/mysql/5.7.22/lib/plugin/caching_sha2_password.so, 2): image not found
Run Code Online (Sandbox Code Playgroud)

我的 Docker compose 文件是这样的:

db:
  image: mysql
  restart: always
  ports:
    - "3306:3306"
  environment:
    MYSQL_ROOT_PASSWORD: password


adminer:
  image: adminer
  restart: always
  ports:
    - 8080:8080
Run Code Online (Sandbox Code Playgroud)

我在我的database.yml中使用它:

default: &default
adapter: mysql2
encoding: utf8
host: 127.0.0.1
username: root
password: password
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
# socket: /Applications/MAMP/tmp/mysql/mysql.sock

development:
  <<: *default
   database: meal_plan_development
Run Code Online (Sandbox Code Playgroud)

为了将我的 Rails 应用程序连接到 mysql docker 映像,我还应该做什么。

Ham*_*ari 6

MySQL 默认身份验证插件

从版本 8 开始,MySQL 使用caching_sha2_password默认身份验证插件。您可以通过在文件中mysql_native_password添加指令来覆盖它,如下所示:commanddocker-compose.yml

db:
   image: mysql
   command: --default-authentication-plugin=mysql_native_password
   restart: always
   ports:
      - "3306:3306"
   environment:
   MYSQL_ROOT_PASSWORD: password

adminer:
   image: adminer
   restart: always
   ports:
     - 8080:8080
Run Code Online (Sandbox Code Playgroud)