# Database Error when starting ghost\_ Error ID : 500, Code: EAI\_AGAIN

**URL:** <https://forum.ghost.org/t/database-error-when-starting-ghost-error-id-500-code-eai-again/30718>\
**Category:** Self-hosting\
**Created:** [June 10, 2022, 1:33pm UTC](https://forum.ghost.org/t/database-error-when-starting-ghost-error-id-500-code-eai-again/30718 "2022-06-10T13:33:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![SasikaA073](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/sasikaa073/32/18140_2.png) [@SasikaA073](https://forum.ghost.org/u/SasikaA073)\
**Post date:** [June 10, 2022, 1:33pm UTC](https://forum.ghost.org/t/database-error-when-starting-ghost-error-id-500-code-eai-again/30718/1 "2022-06-10T13:33:38Z")

</div>

```auto
: [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;

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

---

<div class="post-metadata">

**Author:** ![mjw](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/mjw/32/30781_2.png) [@mjw](https://forum.ghost.org/u/mjw)\
**Post date:** [June 10, 2022, 3:08pm UTC](https://forum.ghost.org/t/database-error-when-starting-ghost-error-id-500-code-eai-again/30718/2 "2022-06-10T15:08:44Z")

</div>

> [@SasikaA073](#):
>
> `ERROR Invalid database host.`

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

---

<div class="post-metadata">

**Author:** ![SasikaA073](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/sasikaa073/32/18140_2.png) [@SasikaA073](https://forum.ghost.org/u/SasikaA073)\
**Post date:** [June 10, 2022, 5:56pm UTC](https://forum.ghost.org/t/database-error-when-starting-ghost-error-id-500-code-eai-again/30718/4 "2022-06-10T17:56:01Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![mjw](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/mjw/32/30781_2.png) [@mjw](https://forum.ghost.org/u/mjw)\
**Post date:** [June 10, 2022, 6:36pm UTC](https://forum.ghost.org/t/database-error-when-starting-ghost-error-id-500-code-eai-again/30718/5 "2022-06-10T18:36:13Z")

</div>

> [@SasikaA073](#):
>
> ```auto
> Message: Error trying to connect to the MySQL database.
> 
> Access denied for user 'root'@'localhost'
> 
> ```

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?

---

<div class="post-metadata">

**Author:** ![SasikaA073](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/sasikaa073/32/18140_2.png) [@SasikaA073](https://forum.ghost.org/u/SasikaA073)\
**Post date:** [June 11, 2022, 3:48am UTC](https://forum.ghost.org/t/database-error-when-starting-ghost-error-id-500-code-eai-again/30718/6 "2022-06-11T03:48:27Z")

</div>

I was setting up the ghost through a [Youtube tutorial](https://www.youtube.com/watch?v=iG0-Z1Ni954&list=PLutaCl3kOXYKI6eSkx2zan28JGUQgUENC), 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](https://linuxhint.com/change-mysql-root-password-ubuntu/) .

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

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

---

<div class="post-metadata">

**Author:** ![mjw](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/mjw/32/30781_2.png) [@mjw](https://forum.ghost.org/u/mjw)\
**Post date:** [June 11, 2022, 8:50am UTC](https://forum.ghost.org/t/database-error-when-starting-ghost-error-id-500-code-eai-again/30718/7 "2022-06-11T08:50:04Z")

</div>

> [@SasikaA073](#):
>
> I was setting up the ghost through a [Youtube tutorial](https://www.youtube.com/watch?v=iG0-Z1Ni954&list=PLutaCl3kOXYKI6eSkx2zan28JGUQgUENC), I didn’t get a prompt to change the password for the root user using this command.

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.

> **[How to install & setup Ghost on Ubuntu 20.04 or 22.04](https://ghost.org/docs/install/ubuntu/)**
>
> A full production install guide for how to install the Ghost professional publishing platform on a production server running Ubuntu 20.04 or 22.04.

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.

> [@How to install Ghost CMS on my VPS](https://forum.ghost.org/t/how-to-install-ghost-cms-on-my-vps/30621/15):
>
> Okay, next steps are to create a database and database user for Ghost. Type sudo mysql and you’ll see a different prompt. This is because you are using MySQL and have left the BASH command-line. You’ll need to replace \<password\> with your password; create a new one for this. create database boringdigital\_com; create user 'user\_boringdigital\_com'@'localhost' identified by '\<password\>'; grant all privileges on boringdigital\_com.\* to 'user\_boringdigital\_com'@'localhost'; flush privileges; quit; P…

---

<div class="post-metadata">

**Author:** ![SasikaA073](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/sasikaa073/32/18140_2.png) [@SasikaA073](https://forum.ghost.org/u/SasikaA073)\
**Post date:** [June 11, 2022, 11:21am UTC](https://forum.ghost.org/t/database-error-when-starting-ghost-error-id-500-code-eai-again/30718/8 "2022-06-11T11:21:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mjw](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/mjw/32/30781_2.png) [@mjw](https://forum.ghost.org/u/mjw)\
**Post date:** [June 11, 2022, 11:30am UTC](https://forum.ghost.org/t/database-error-when-starting-ghost-error-id-500-code-eai-again/30718/9 "2022-06-11T11:30:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tchangth](https://avatars.discourse-cdn.com/v4/letter/t/779978/32.png) [@tchangth](https://forum.ghost.org/u/tchangth)\
**Post date:** [October 13, 2022, 12:05am UTC](https://forum.ghost.org/t/database-error-when-starting-ghost-error-id-500-code-eai-again/30718/10 "2022-10-13T00:05:32Z")

</div>

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)
