docker 如何连接openedx tutor的mysql数据库?

tktrz96b  于 2023-01-25  发布在  Docker
关注(0)|答案(1)|浏览(149)
    • 注:**
  • 不管是谁把这个问题标记为"与软件开发无关",我知道这一定很难不花时间去做任何事情,比把软件开发相关的问题标记为无关更重要的是提高你的自我重要性,这在这一点上显然是痛苦的或不存在的。所以我理解你为什么这么做。我很抱歉,如果这个问题没有结束(也不会结束),不要让它影响你的热情,希望否决我的问题有助于减轻你的痛苦,但它毕竟不会让你成为Maven,我担心。
  • 如果有一种方法可以完全在Docker之外运行整个事情,指出文档中解决了这个问题(如果存在的话)/指定如何这样做,将会非常感激。

我正在尝试连接到运行在docker中的mysql数据库,该数据库由tutor调用:

tutor dev launch

生成下面的config.yml文件

CMS_HOST: studio.local.overhang.io
CMS_OAUTH2_SECRET: ue5LfJvi7LyJ5d0kN1mKwXWH
CONTACT_EMAIL: contact@local.overhang.io
ENABLE_HTTPS: false
ID: e7t5Qli0r4Ue4qePDDKP3yHb
JWT_RSA_PRIVATE_KEY: '-----BEGIN RSA PRIVATE KEY-----

  MIIEogIBAAKCAQEA5CGyUuSGEoUkgeRQpjpQyZmhPY7YtVIdsNzGaYGjC3XJC3ZT

  3BhQTR0M4xrEXONDueODk5ReRwDRMtWmuJo57gDnK0yQ+3mNiCB5Vzuz7q90tMWb

  oTsX9wcvOCOqlWXvW/BKaNpB872pRo7yPA2BBmsAZuA0lOf42oyhEep/LgHk9XQr

  LHD5l6y6uWIsxMorCmw19pn987RgyHcs0ewFOY6M/ftnnMFus0b+tc3t3x6llfRe

  /WTvEEC1MFjSGnawXDWU6b14RJYgBX6owHUZr3yUY8ROcklIGYferWbG3K8JwRui

  RyboorrwGfGUcFpKgkLwFJq4k+ut6Fgxmf1I9QIDAQABAoIBAE7ZxsUX769fDatH

  uwh5h4rm6vBX+1dQtqp25K16/Vvsrjyj/YBJdxfwPpAQpGZmtvX9SXEtCxkHk0c6

  yZFs3TECZuR0ZnhFH0I51zbrj9mkE3aYBp7HyhS8Cvog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Qb2AMKt

  eBty8RjunNs2dt9n4l2VrWeIFiNKlR8el/RzXk4ZhcW84KTq7mM=

  -----END RSA PRIVATE KEY-----'
LANGUAGE_CODE: en
LMS_HOST: local.overhang.io
MYSQL_ROOT_PASSWORD: 9vXd2uA6
OPENEDX_MYSQL_PASSWORD: esJCvsog
OPENEDX_SECRET_KEY: R6m93ga6apJcYJDjCMSUrPNF
PLATFORM_NAME: My Open edX
PLUGINS:
- mfe

所以我假设用户是root,密码是9vXd2uA6esJCvsog,不确定是哪一个,所以我等到mysql容器启动:

================================================
        Database creation and migrations
================================================
Initialising all services...
Running init task in mysql
docker-compose -f tutor/tutor-dev/env/local/docker-compose.yml -f tutor/tutor-dev/env/dev/docker-compose.yml -f tutor/tutor-dev/env/dev/docker-compose.tmp.yml --project-name tutor_dev -f tutor/tutor-dev/env/local/docker-compose.jobs.yml -f tutor/tutor-dev/env/dev/docker-compose.jobs.yml -f tutor/tutor-dev/env/dev/docker-compose.jobs.tmp.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="9vXd2uA6" --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="9vXd2uA6" --host "mysql" --port 3306 -e "CREATE DATABASE IF NOT EXISTS openedx;"
mysql -u root --password="9vXd2uA6" --host "mysql" --port 3306 -e "CREATE USER IF NOT EXISTS '"'"'openedx'"'"';"
mysql -u root --password="9vXd2uA6" --host "mysql" --port 3306 -e "ALTER USER '"'"'openedx'"'"'@'"'"'%'"'"' IDENTIFIED BY '"'"'esJCvsog'"'"';"
mysql -u root --password="9vXd2uA6" --host "mysql" --port 3306 -e "GRANT ALL ON openedx.* TO '"'"'openedx'"'"'@'"'"'%'"'"';"'
[+] Running 1/0
 ⠿ Container tutor_dev-mysql-1  Running                                    0.0s
Initialising MySQL...
mysql: [Warning] Using a password on the command line interface can be insecure.
MySQL is up and running

我试着

% mysql -u root --password="9vXd2uA6" --port 3306 -h mysql
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (8)

以及

% mysql -u root --password="9vXd2uA6" --port 3306
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

以及

% docker ps
CONTAINER ID   IMAGE                                            COMMAND                  CREATED         STATUS         PORTS                    NAMES
8e4c6ab90f55   openedx-dev:15.2.0                               "celery --app=cms.ce…"   5 minutes ago   Up 4 minutes   8000/tcp                 tutor_dev-cms-worker-1
75ed5ee2ef21   openedx-dev:15.2.0                               "./manage.py cms run…"   5 minutes ago   Up 4 minutes   0.0.0.0:8001->8000/tcp   tutor_dev-cms-1
4f94ee5fd720   overhangio/openedx-gradebook-dev:15.0.4          "docker-entrypoint.s…"   5 minutes ago   Up 4 minutes   0.0.0.0:1994->1994/tcp   tutor_dev-gradebook-1
e28c194381b0   overhangio/openedx-account-dev:15.0.4            "docker-entrypoint.s…"   5 minutes ago   Up 4 minutes   0.0.0.0:1997->1997/tcp   tutor_dev-account-1
1707bf5263f7   openedx-dev:15.2.0                               "celery --app=lms.ce…"   5 minutes ago   Up 4 minutes   8000/tcp                 tutor_dev-lms-worker-1
3a76937f82a1   overhangio/openedx-authn-dev:15.0.4              "docker-entrypoint.s…"   5 minutes ago   Up 4 minutes   0.0.0.0:1999->1999/tcp   tutor_dev-authn-1
821e6fa12f1f   overhangio/openedx-profile-dev:15.0.4            "docker-entrypoint.s…"   5 minutes ago   Up 4 minutes   0.0.0.0:1995->1995/tcp   tutor_dev-profile-1
30685779c278   overhangio/openedx-course-authoring-dev:15.0.4   "docker-entrypoint.s…"   5 minutes ago   Up 4 minutes   0.0.0.0:2001->2001/tcp   tutor_dev-course-authoring-1
7657705346b6   overhangio/openedx-learning-dev:15.0.4           "docker-entrypoint.s…"   5 minutes ago   Up 4 minutes   0.0.0.0:2000->2000/tcp   tutor_dev-learning-1
f3289604200e   overhangio/openedx-discussions-dev:15.0.4        "docker-entrypoint.s…"   5 minutes ago   Up 4 minutes   0.0.0.0:2002->2002/tcp   tutor_dev-discussions-1
0111b9ee8228   openedx-dev:15.2.0                               "./manage.py lms run…"   5 minutes ago   Up 4 minutes   0.0.0.0:8000->8000/tcp   tutor_dev-lms-1
1aa5c71a9e38   mongo:4.2.17                                     "docker-entrypoint.s…"   5 minutes ago   Up 5 minutes   27017/tcp                tutor_dev-mongodb-1
d1a62a1e4f39   redis:6.2.6                                      "docker-entrypoint.s…"   5 minutes ago   Up 5 minutes   6379/tcp                 tutor_dev-redis-1
89ba0c7d746b   elasticsearch:7.10.1                             "/tini -- /usr/local…"   5 minutes ago   Up 5 minutes   9200/tcp, 9300/tcp       tutor_dev-elasticsearch-1
7274bb8cc66b   mysql:5.7.35                                     "docker-entrypoint.s…"   5 minutes ago   Up 5 minutes   3306/tcp, 33060/tcp      tutor_dev-mysql-1

那么下面的所有也失败:

% docker run -it mysql:5.7.35 bash
root@b862b4a24e28:/# mysql -u root --password="9vXd2uA6" --port 3306
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
root@b862b4a24e28:/# mysql -u root --password="9vXd2uA6" --port 3306^C
root@b862b4a24e28:/# mysql -u root --password="9vXd2uA6" --port 3306 -h mysql
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host 'mysql' (22)
root@b862b4a24e28:/# mysql -u root --password="esJCvsog" --port 3306         
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
jdgnovmf

jdgnovmf1#

在这种情况下,我建议从头开始。
使用这些命令可以再次初始化MySQL。

tutor dev stop
sudo rm -rf "$(tutor config printroot)/data/mysql"
tutor dev launch

如果问题仍然存在,请留下评论。

相关问题