Been seeing this go years back. No one seems to have an answer, and those who know aren't saying anything.
getaddrinfo for mysql failed: nodename nor servname provided
Ok, this is a really weird one. I have my environment set up in docker and whenever I'm developing, I run sail up to start all the containers and I'm off to the races. The last time I did any development on my site was on Sunday and everything was working great. Today, however, when I try to access my pages, I'm getting the following error:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: nodename nor servname provided
Now, I know what you are going to say -- something changed in your .env file w/r/t connection information. Except that it didn't. These are the settings I have:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
FORWARD_DB_PORT=3306
DB_DATABASE=communal_haven
DB_USERNAME=root
DB_PASSWORD=IM_NOT_THAT_CRAZY
When I run php artisan serve (on my local machine, which is where I've always run it), this is what I'm seeing as it pertains to the MySQL image:
communal-haven-mysql-1 | 2022-01-25T23:23:05.676945Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.27) starting as process 1
communal-haven-mysql-1 | 2022-01-25T23:23:05.686315Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
communal-haven-mysql-1 | 2022-01-25T23:23:05.820621Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
communal-haven-mysql-1 | 2022-01-25T23:23:06.019745Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
communal-haven-mysql-1 | 2022-01-25T23:23:06.019797Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
communal-haven-mysql-1 | 2022-01-25T23:23:06.020758Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
communal-haven-mysql-1 | 2022-01-25T23:23:06.020819Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
communal-haven-mysql-1 | 2022-01-25T23:23:06.048244Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
communal-haven-mysql-1 | 2022-01-25T23:23:06.048491Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.27' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
As far as I can tell, everything looks copacetic there.
In docker, for my server image (sail-8.0/app), I open it up in the CLI and from that command line I can run
root@6406065745f6:/var/www/html# mysql -h mysql -u root -p
(where that second mysql is what is set up as the DB_HOST in the .env file) and I'm able to connect to it just fine. Additionally, if I run php artisan tinker while on that command line I can run User::get() no problem to retrieve all the users.
I'm not sure what else to look at/for because as far as I can tell, everything is working as it should. I don't suppose anyone has any ideas as to where I can look next?
EDIT: What's interesting is if, in my site docker shell, I run php artisan serve there then it starts working again. As stated previously, I would always run that on my local machine (outside of docker) and it never had a problem connecting to MySQL prior to today.
christoph
Please or to participate in this conversation.