Laravel/Mysql php_network_getaddresses: getaddrinfo for mysql failed: Name or service not known

Hi there, first time trying to deploy on fly here. I have been following the Laravel/Mysql guide on fly but am running into an issue.

The Lararavel app on fly is working. Any route that doesn’t call the db works fine and I get the data.

But on any route that calls the db, I get this error in my logs:

2024-07-24T03:36:51.990 app[7811ed3b545648] sea [info] {"message":"SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Name or service not known (Connection: mysql, SQL: select * from `user_books`)","context":{"exception":{"class":"Illuminate\\Database\\QueryException","message":"SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Name or service not known (Connection: mysql, SQL: select * from `user_books`)","code":2002,"file":"/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:829","previous":{"class":"PDOException","message":"SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Name or service not known","code":2002,"file":"/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:65","previous":{"class":"PDOException","message":"PDO::__construct(): php_network_getaddresses: getaddrinfo for mysql failed: Name or service not known","code":0,"file":"/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connectors/Conn

2024-07-24T03:36:51.990 app[7811ed3b545648] sea [info] ector.php:65"}}}},"level":400,"level_name":"ERROR","channel":"production","datetime":"2024-07-24T03:36:51.990122+00:00","extra":{}}

Here is my main Laravel app fly.toml

# fly.toml app configuration file generated for bookshelf-app-backend on 2024-07-21T21:04:15-07:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'bookshelf-app-backend'
primary_region = 'sea'
console_command = 'php /var/www/html/artisan tinker'

[build]
  [build.args]
    NODE_VERSION = '18'
    PHP_VERSION = '8.1'

[env]
  APP_ENV = 'production'
  LOG_CHANNEL = 'stderr'
  LOG_LEVEL = 'info'
  LOG_STDERR_FORMATTER = 'Monolog\Formatter\JsonFormatter'
  SESSION_DRIVER = 'cookie'
  SESSION_SECURE_COOKIE = 'true'
  DB_CONNECTION = 'mysql'
  DB_HOST = 'bookshelf-db.internal'
  DB_DATABASE = 'bookshelf'

[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ['app']

[[vm]]
  memory = '1gb'
  cpu_kind = 'shared'
  cpus = 1

I have a secong mysql App on fly, and here is it’s toml file, in a subdirectory in my main app

# Keep your own app name
app = 'bookshelf-db'
# Keep your own primary region
primary_region = "sea"

[build]
  image = 'mysql:8'

[[vm]]
  cpu_kind = 'shared'
  cpus = 1
  memory_mb = 2048

# The [processes] section is different for 8+, 8.4, and 5.7. Use the one that matches your version.
# Use the following for versions 8 to 8.3:
[processes]
  app = """--datadir /data/mysql \
    --default-authentication-plugin mysql_native_password"""

# Uncomment and use the following for 8.4:
# [processes]
#  app = """--datadir /data/mysql \
#    --mysql-native-password=ON"""

# Uncomment and use the following for 5.7:
# [processes]
#  app = "--datadir /data/mysql"

# Add the following sections for all versions
[mounts]
  source = "mysqldata"
  destination = "/data"

[env]
  MYSQL_DATABASE = "bookshelf"
  MYSQL_USER = "bookshelf_user"

Then i tried to access it locally with:

flyctl proxy 3306 -a bookshelf-db

And got this error:
Error: bookshelf-db.internal: host was not found in DNS

I also have the db/mysql secrets set as per the guides

Any help in resolving this would be greatly appreciated!
Thanks

I’ve also been getting this error in my mysql app

mysqld: Table 'mysql.plugin' doesn't exist

and I did the recommended fix of renaming the directory and redeploying, but this doesn’t seem to have done anything

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