Database Error when starting ghost_ Error ID : 500, Code: EAI_AGAIN

: [2022-06-10 13:16:37] ERROR Invalid database host.
: Invalid database host.
: "Please double check your database config."
: Error ID:
:     500
: Error Code:
:     EAI_AGAIN
: ----------------------------------------
: **Error: getaddrinfo EAI_AGAIN database**
**:     at /var/www/ghost2/versions/5.2.2/node_modules/knex-migrator/lib/database.js:50:23**
**:     at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)**

I ran into this error when hosting ghost in AWS. These are my;

Debug Information:
    OS: Ubuntu, v20.04.4 LTS
    Node Version: v16.15.1
    Ghost Version: 5.2.2
    Ghost-CLI Version: 1.21.0
    Environment: production
    Command: 'ghost setup'

Please help me. Thanks in advance for helping me!

Is the MySQL database server running? Have to specified the correct URI, credentials etc.?

✖ Starting Ghost
One or more errors occurred.

1) CliError

Message: Error trying to connect to the MySQL database.
Help: You can run `ghost config` to re-enter the correct credentials. Alternatively you can run `ghost setup` again.


2) GhostError

Message: Ghost was able to start, but errored during boot with: Access denied for user 'root'@'localhost'
Help: Unknown database error
Suggestion: journalctl -u ghost_sasikaspace-ml-1 -n 50

Debug Information:
    OS: Ubuntu, v18.04.6 LTS
    Node Version: v16.15.1
    Ghost Version: 5.2.2
    Ghost-CLI Version: 1.21.0
    Environment: production
    Command: 'ghost install'

Additional log info available in: /home/ubuntu/.ghost/logs/ghost-cli-debug-2022-06-10T17_51_28_864Z.log

Try running ghost doctor to check your system for known issues.

You can always refer to https://ghost.org/docs/ghost-cli/ for troubleshooting.
ubuntu@ip-172-31-19-178:/var/www/ghost2$ ghost config

Love open source? We’re hiring Node.js Engineers to work on Ghost full-time.
https://careers.ghost.org/product-engineer-node-js


ubuntu@ip-172-31-19-178:/var/www/ghost2$

This is the issue I faced. It says that the database server is running.

ubuntu@ip-172-31-19-178:/var/www/ghost2$ sudo systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2022-06-10 17:38:17 UTC; 16min ago
 Main PID: 29387 (mysqld)
    Tasks: 28 (limit: 1134)
   CGroup: /system.slice/mysql.service
           └─29387 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

Jun 10 17:38:16 ip-172-31-19-178 systemd[1]: Starting MySQL Community Server...
Jun 10 17:38:17 ip-172-31-19-178 systemd[1]: Started MySQL Community Server.
1 Like

The error messages are quite explicit. Are your credentials correct, i.e., did you enter them correctly when setting up Ghost, or does the database user have the correct permissions for the database?

Have you checked? Did ghost setup complete without error? Did you create a MySQL database and user for Ghost?

I was setting up the ghost through a Youtube tutorial, I didn’t get a prompt to change the password for the root user using this command. In the video, he got a pink color prompt to change the password, He was using Ubuntu 16 Lts server instance, and I was using Ubuntu 22,18 (I checked different versions, and got the same result)
sudo apt-get install mysql-server

Then, I changed the password for the root user using this post .

These are all the commands that I used when setting up the AWS EC2 instance from the beginning.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nginx
sudo ufw allow 'Nginx Full'
sudo apt-get install mysql-server
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash
sudo apt-get install -y nodejs
sudo npm install ghost-cli@latest --location=global 
ghost help 
sudo mkdir -p /var/www/ghost
sudo chown ubuntu:ubuntu /var/www/ghost
sudo chmod 775 /var/www/ghost
cd /var/www/ghost
ghost install

Yes, ghost setup threw some errors. Those errors were mentioned in the previous reply.

I am new to MySQL and AWS. I understand very little about those error messages.

And your effort of helping me out is ineffable, thanks heaps.

It’s best to start with the official guide. So, read this through first to be sure you understand. Also, note that Ubuntu 22.04 isn’t supported, even though it may work.

To attempt to recover your setup, follow this thread from this post. It will show you how to setup MySQL, and restart the installation process. You’ll need to substitute some parts with your site details.

1 Like

Thank you so much! I could resolve the error by following this guide.

2 Likes

Thanks for the update; it’s good to learn that you are up and running with Ghost. Please mark my last post as the solution.

The documentation mentioned to use root (as a user) and key in the password of root (during ghost setup) - BUT if you are in a hurry to install apt install mysql-server, there is no root password specified - u can try mysql -u root -p (enter) and you will go straight to mysql prompt.

If you put in the root password during the setup it will fail the setup (as ghost user could not be set up and therefore the rest does not fall in place. The solution for me is to create a non-root user and ghost user manually like this:
CREATE USER ‘test’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;
GRANT ALL PRIVILEGES ON . TO ‘test’@‘localhost’ WITH GRANT OPTION;

Do the same for ‘ghost’@‘localhost’
During Ghost setup enter test (and not root) and when come to set up ghost user pick n (for no)

Of course, this is meant for POC (proof of concept)