Cannot connect to MySQL database from Elixir/Phoenix app

In my Elixir Phoenix app, I have:

  username = System.fetch_env!("MYSQL_USERNAME")
  password = System.fetch_env!("MYSQL_PASSWORD")
  hostname = System.fetch_env!("MYSQL_HOSTNAME")
  database = System.fetch_env!("MYSQL_DATABASE")

  config :arvore, Arvore.Repo,
    username: username,
    password: password,
    hostname: hostname,
    database: database,
    stacktrace: true,
    protocol: :tcp,
    show_sensitive_data_on_connection_error: false,
    pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
    socket_options: [:inet6]

I’ve made sure that the connection supports IPV6 and uses TCP. My username, password and database are correct, and for the hostname, I’m using: “db-app-name.internal” just like the docs suggested.

I get this error every time I try to deploy:

   INFO Preparing to run: `/app/bin/migrate` as nobody
   INFO [fly api proxy] listening at /.fly/api
  2023/09/08 17:17:04 listening on [fdaa:2:f9ff:a7b:d5:cbd:b2ec:2]:22 (DNS: [fdaa::3]:53)
  ** (EXIT from #PID<0.95.0>) shutdown
   INFO Main child exited normally with code: 1
   INFO Starting clean up.
   WARN hallpass exited, pid: 267, status: signal: 15 (SIGTERM)
  2023/09/08 17:17:05 listening on [fdaa:2:f9ff:a7b:d5:cbd:b2ec:2]:22 (DNS: [fdaa::3]:53)
  [    2.306350] reboot: Restarting system
  machine restart policy set to 'no', not restarting
Error: release command failed - aborting deployment. error release_command machine 32874435c00dd8 exited with non-zero status of 1

I am able to proxy the MySQL database with: “flyctl proxy 3306 -a arvore-vitorlimadev-mysql”

What I am doing wrong?

Hey there,

Would you mind posting your fly.toml file? It would help give us a more detailed look into what’s going on exactly.

@kaelynH

Phoenix toml:

app = "arvore-vitorlimadev"
primary_region = "gig"
kill_signal = "SIGTERM"
swap_size_mb = 512

[build]

[deploy]
  release_command = "/app/bin/migrate"

[env]
  PHX_HOST = "arvore-vitorlimadev.fly.dev"
  PORT = "8080"

[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ["app"]
  [http_service.concurrency]
    type = "connections"
    hard_limit = 1000
    soft_limit = 1000

The MySQL toml:

app = "arvore-vitorlimadev-mysql"
kill_signal = "SIGINT"
kill_timeout = 5

primary_region = "gig"

[processes]
  app = "--datadir /data/mysql --default-authentication-plugin mysql_native_password --performance-schema=OFF --innodb-buffer-pool-size 64M"

[mounts]
  source="mysqldata"
  destination="/data"

[env]
  MYSQL_DATABASE = "..."
  MYSQL_USER = "..."

# As of 04/25/2023:
# MySQL 8.0.33 has a bug in it
# so avoid that specific version
[build]
  image = "mysql:8.0.32"

I’m using “arvore-vitorlimadev-mysql.internal” in the MYSQL_HOST variable.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.