# Laravel/Mysql php\_network\_getaddresses: getaddrinfo for mysql failed: Name or service not known

**URL:** <https://community.fly.io/t/laravel-mysql-php-network-getaddresses-getaddrinfo-for-mysql-failed-name-or-service-not-known/20937>\
**Category:** Questions / Help\
**Tags:** laravel, databases, mysql, login-only\
**Created:** [July 24, 2024, 3:49am UTC](https://community.fly.io/t/laravel-mysql-php-network-getaddresses-getaddrinfo-for-mysql-failed-name-or-service-not-known/20937 "2024-07-24T03:49:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh360](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/josh360/32/37058_2.png) [@josh360](https://community.fly.io/u/josh360)\
**Post date:** [July 24, 2024, 3:49am UTC](https://community.fly.io/t/laravel-mysql-php-network-getaddresses-getaddrinfo-for-mysql-failed-name-or-service-not-known/20937/1 "2024-07-24T03:49:02Z")

</div>

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:

```auto
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

```auto
# 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

```auto
# 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:

```auto
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

---

<div class="post-metadata">

**Author:** ![josh360](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/josh360/32/37058_2.png) [@josh360](https://community.fly.io/u/josh360)\
**Post date:** [July 25, 2024, 12:41am UTC](https://community.fly.io/t/laravel-mysql-php-network-getaddresses-getaddrinfo-for-mysql-failed-name-or-service-not-known/20937/2 "2024-07-25T00:41:58Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/fly1/original/3X/6/e/6e8955d00cb218e186ebbe3a6ab06fefdce15290.svg) [@system](https://community.fly.io/u/system)\
**Post date:** [August 1, 2024, 12:42am UTC](https://community.fly.io/t/laravel-mysql-php-network-getaddresses-getaddrinfo-for-mysql-failed-name-or-service-not-known/20937/3 "2024-08-01T00:42:01Z")

</div>

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