MySQL container not running on tutor dev launch: Unknown MySQL server host 'mysql' (-2)

I am trying to set up tutor to run Open Edx for local development. I am using Tutor nightly with open-edx master branch. After running tutor dev launch command, I am getting the following error:

Running init task in mysql
docker compose -f '/Users/ahmed_zubair/Library/Application Support/tutor-nightly/env/local/docker-compose.yml' -f '/Users/ahmed_zubair/Library/Application Support/tutor-nightly/env/dev/docker-compose.yml' --project-name tutor_nightly_dev -f '/Users/ahmed_zubair/Library/Application Support/tutor-nightly/env/local/docker-compose.jobs.yml' -f '/Users/ahmed_zubair/Library/Application Support/tutor-nightly/env/dev/docker-compose.jobs.yml' run --rm mysql-job sh -e -c 'echo "Initialising MySQL..."
mysql_connection_max_attempts=10
mysql_connection_attempt=0
until mysql -u root --password="LL9jyNgF" --host "mysql" --port 3306 -e '"'"'exit'"'"'
do
    mysql_connection_attempt=$(expr $mysql_connection_attempt + 1)
    echo "    [$mysql_connection_attempt/$mysql_connection_max_attempts] Waiting for MySQL service (this may take a while)..."
    if [ $mysql_connection_attempt -eq $mysql_connection_max_attempts ]
    then
      echo "MySQL initialisation error" 1>&2
      exit 1
    fi
    sleep 10
done
echo "MySQL is up and running"

# edx-platform database
mysql -u root --password="LL9jyNgF" --host "mysql" --port 3306 -e "CREATE DATABASE IF NOT EXISTS openedx;"
mysql -u root --password="LL9jyNgF" --host "mysql" --port 3306 -e "CREATE USER IF NOT EXISTS '"'"'openedx'"'"';"
mysql -u root --password="LL9jyNgF" --host "mysql" --port 3306 -e "ALTER USER '"'"'openedx'"'"'@'"'"'%'"'"' IDENTIFIED BY '"'"'kz6YMlw1'"'"';"
mysql -u root --password="LL9jyNgF" --host "mysql" --port 3306 -e "GRANT ALL ON openedx.* TO '"'"'openedx'"'"'@'"'"'%'"'"';"'
[+] Running 1/0
 ⠿ Container tutor_nightly_dev-mysql-1  Started                            0.0s
Initialising MySQL...
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on 'mysql:3306' (113)
    [1/10] Waiting for MySQL service (this may take a while)...
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
    [2/10] Waiting for MySQL service (this may take a while)...
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
    [3/10] Waiting for MySQL service (this may take a while)...
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
    [4/10] Waiting for MySQL service (this may take a while)...
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
    [5/10] Waiting for MySQL service (this may take a while)...
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
    [6/10] Waiting for MySQL service (this may take a while)...
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
    [7/10] Waiting for MySQL service (this may take a while)...
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
    [8/10] Waiting for MySQL service (this may take a while)...
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
    [9/10] Waiting for MySQL service (this may take a while)...
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (-2)
    [10/10] Waiting for MySQL service (this may take a while)...
MySQL initialisation error
Error: Command failed with status 1: docker compose -f /Users/ahmed_zubair/Library/Application Support/tutor-nightly/env/local/docker-compose.yml -f /Users/ahmed_zubair/Library/Application Support/tutor-nightly/env/dev/docker-compose.yml --project-name tutor_nightly_dev -f /Users/ahmed_zubair/Library/Application Support/tutor-nightly/env/local/docker-compose.jobs.yml -f /Users/ahmed_zubair/Library/Application Support/tutor-nightly/env/dev/docker-compose.jobs.yml run --rm mysql-job sh -e -c echo "Initialising MySQL..."
mysql_connection_max_attempts=10
mysql_connection_attempt=0
until mysql -u root --password="LL9jyNgF" --host "mysql" --port 3306 -e 'exit'
do
    mysql_connection_attempt=$(expr $mysql_connection_attempt + 1)
    echo "    [$mysql_connection_attempt/$mysql_connection_max_attempts] Waiting for MySQL service (this may take a while)..."
    if [ $mysql_connection_attempt -eq $mysql_connection_max_attempts ]
    then
      echo "MySQL initialisation error" 1>&2
      exit 1
    fi
    sleep 10
done
echo "MySQL is up and running"

# edx-platform database
mysql -u root --password="LL9jyNgF" --host "mysql" --port 3306 -e "CREATE DATABASE IF NOT EXISTS openedx;"
mysql -u root --password="LL9jyNgF" --host "mysql" --port 3306 -e "CREATE USER IF NOT EXISTS 'openedx';"
mysql -u root --password="LL9jyNgF" --host "mysql" --port 3306 -e "ALTER USER 'openedx'@'%' IDENTIFIED BY 'kz6YMlw1';"
mysql -u root --password="LL9jyNgF" --host "mysql" --port 3306 -e "GRANT ALL ON openedx.* TO 'openedx'@'%';"

This is what I see on logs for mysql container:

2023-11-17 02:29:54 2023-11-16T21:29:54.830347Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2023-11-17 02:29:54 2023-11-16T21:29:54.832041Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2023-11-17 02:29:54 2023-11-16T21:29:54.832120Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.1.0) initializing of server in progress as process 41
2023-11-17 02:29:54 2023-11-16T21:29:54.833486Z 0 [Warning] [MY-013243] [Server] --character-set-server: The character set UTF8MB3 is deprecated and will be removed in a future release. Please consider using UTF8MB4 instead.
2023-11-17 02:29:54 2023-11-16T21:29:54.833492Z 0 [Warning] [MY-013244] [Server] --collation-server: 'utf8mb3_general_ci' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.
2023-11-17 02:29:54 2023-11-16T21:29:54.835946Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2023-11-17 02:29:54 2023-11-16T21:29:54.835951Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2023-11-17 02:29:54 2023-11-16T21:29:54.836025Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-11-17 02:29:54 2023-11-16T21:29:54.836144Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.1.0)  MySQL Community Server - GPL.
2023-11-17 02:29:54 2023-11-16T21:29:54.836389Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
2023-11-17 02:28:54 2023-11-16 21:28:54+00:00 [Note] [Entrypoint]: Initializing database files
2023-11-17 02:29:54 2023-11-16 21:29:54+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.1.0-1.el8 started.
2023-11-17 02:29:54 2023-11-16 21:29:54+00:00 [Note] [Entrypoint]: Initializing database files
2023-11-17 02:30:55 2023-11-16 21:30:55+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.1.0-1.el8 started.
2023-11-17 02:30:55 2023-11-16 21:30:55+00:00 [Note] [Entrypoint]: Initializing database files
2023-11-17 02:30:55 2023-11-16T21:30:55.506212Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2023-11-17 02:30:55 2023-11-16T21:30:55.507910Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2023-11-17 02:30:55 2023-11-16T21:30:55.507988Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.1.0) initializing of server in progress as process 41
2023-11-17 02:30:55 2023-11-16T21:30:55.509316Z 0 [Warning] [MY-013243] [Server] --character-set-server: The character set UTF8MB3 is deprecated and will be removed in a future release. Please consider using UTF8MB4 instead.
2023-11-17 02:30:55 2023-11-16T21:30:55.509323Z 0 [Warning] [MY-013244] [Server] --collation-server: 'utf8mb3_general_ci' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.
2023-11-17 02:30:55 2023-11-16T21:30:55.511698Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2023-11-17 02:30:55 2023-11-16T21:30:55.511703Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2023-11-17 02:30:55 2023-11-16T21:30:55.511790Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-11-17 02:30:55 2023-11-16T21:30:55.511913Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.1.0)  MySQL Community Server - GPL.
2023-11-17 02:30:55 2023-11-16T21:30:55.512147Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.

I cant figure why I am seeing this error message “initialize specified but the data directory has files in it. Aborting” in the container

I was able to resolve this issue by going into “tutor-nightly/data” and deleting the “mysql” folder manually. After that didnt faced this issue

1 Like

This also may be helpful: