简体   繁体   English

exec: \\“mysql\\”: 在 $PATH 中找不到可执行文件": 未知

[英]exec: \“mysql\”: executable file not found in $PATH": unknown

I've created a container based on the mysql:5.7 image.我已经基于 mysql:5.7 图像创建了一个容器。 Then I set the password with this然后我用这个设置密码

docker run --name mysql -v $(pwd):/src -e MYSQL_ROOT_PASSWORD=password -d mysql:5.7

Then I deployed my modules using docker-compose up -d on my docker-compose.yml file.然后我在我的 docker-compose.yml 文件上使用 docker-compose up -d 部署了我的模块。 Apparently, it raised an显然,它提出了一个

exec: \\"mysql\\": executable file not found in $PATH": unknown

error and my 2 other modules also are having errors that keeps on restarting and point to mysql.错误和我的其他 2 个模块也有错误,不断重新启动并指向 mysql。 I can import Python files in Django shell as well as mysql -u root -p but I cannot use the imports when it can't connect to the database.我可以在 Django shell 和mysql -u root -p导入 Python 文件,但是当它无法连接到数据库时我不能使用导入。

Things I did based on my research:我根据我的研究所做的事情:

  1. I've set my Windows 10 environment variables to point at C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin where mysql.exe resides.我已将 Windows 10 环境变量设置为指向 mysql.exe 所在的C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin It still didn't work.它仍然没有奏效。
  2. mysql-init.txt (REF: https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html ): This runs the mysql prompt successfully. mysql-init.txt (REF: https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html ):这会成功运行 mysql 提示。

    grant all privileges on *.* to root@localhost;

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

docker-compose.yml docker-compose.yml

version: '2'
services:
  # Mysql
  mysql:
    image: mysql:5.7
    restart: always
    hostname: mysql
    container_name: mysql
    environment:
      - MYSQL_USER=root
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_DB=bitpal
    ports:
      - "3306:3306"


  # Redis
  redis:
    image: redis:latest
    restart: always
    hostname: redis
    container_name: redis
    ports:
      - "6379:6379"


  # Django web server
  bitpal:
    image: python:3.5
    restart: always
    hostname: bitpal
    container_name: bitpal
    working_dir: /bitpal
    command: ./bin/start_dev.sh
    volumes:
      - ./bitpal:/bitpal
      - ./etc/config:/etc/config
      - ./log:/log
    ports:
      - "80:80"
    links:
      - mysql
      - redis
    depends_on:
      - mysql
    environment:
      # Database
      - DB_NAME=bitpal
      - DB_USER=root
      - DB_PASSWORD=password
      - DB_HOST=mysql
      - DB_PORT=3306


  # Celery worker
  worker:
    image: python:3.5
    restart: always
    container_name: worker
    command: bash -c "./bin/install.sh && ./bin/celery_worker.sh"
    working_dir: /bitpal
    volumes:
      - ./bitpal:/bitpal
      - ./etc/config:/etc/config
      - ./log:/log
    links:
      - mysql
      - redis
    depends_on:
      - redis


  # Bitshares websocket listener
  websocket_listener:
    image: python:3.5
    restart: always
    container_name: websocket_listener
    command: bash -c "./bin/install.sh && ./bin/websocket_listener.sh"
    working_dir: /bitpal
    volumes:
      - ./bitpal:/bitpal
      - ./etc/config:/etc/config
      - ./log:/log
    links:
      - mysql
      - redis
    depends_on:
      - redis


  # Nginx
  nginx:
    image: nginx:1.12.1
    container_name: nginx
    ports:
      - "8000:80"
    volumes:
      - ./bitpal:/home/bitpal/bitpal/bitpal
      - ./nginx:/etc/nginx/conf.d
    depends_on:
      - bitpal

Dockerfile文件

FROM python:3.5

RUN mkdir -p /bitpal

WORKDIR /bitpal
EXPOSE 80

ADD requirement.txt /bitpal/
RUN python3.5 -m pip install -r /bitpal/requirement.txt

settings.py设置.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'bitpal',
        'USER': 'root',
        'PASSWORD': 'password',
        'HOST': SECRETS['db']['default']['hostname'],
        'PORT': '3306',
        'OPTIONS': {'autocommit': SECRETS['db']['default']['commit']}
    }
}

docker version码头工人版本

Client:
 Version:       18.03.0-ce
 API version:   1.37
 Go version:    go1.9.4
 Git commit:    0520e24
 Built: Wed Mar 21 23:06:28 2018
 OS/Arch:       windows/amd64
 Experimental:  false
 Orchestrator:  swarm

Server:
 Engine:
  Version:      18.04.0-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.4
  Git commit:   3d479c0
  Built:        Tue Apr 10 18:23:35 2018
  OS/Arch:      linux/amd64
  Experimental: false

docker info码头工人信息

Containers: 6
 Running: 3
 Paused: 0
 Stopped: 3
Images: 6
Server Version: 18.04.0-ce
Storage Driver: aufs
 Root Dir: /mnt/sda1/var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 46
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.93-boot2docker
Operating System: Boot2Docker 18.04.0-ce (TCL 8.2.1); HEAD : b8a34c0 - Wed Apr 11 17:00:55 UTC 2018
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 995.6MiB
Name: default
ID: I7DZ:5SQN:EOBV:PJOE:YHNK:RSXK:F6EH:4J7P:LSTI:CR2M:E2MV:VI27
Docker Root Dir: /mnt/sda1/var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
 provider=virtualbox
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

docker inspect mysql:5.7码头工人检查 mysql:5.7

[
    {
        "Id": "sha256:0d16d0a97dd13a8ca0c0e205ce1f31f64d9d32048379eb322749442bff35f144",
        "RepoTags": [
            "mysql:5.7"
        ],
        "RepoDigests": [
            "mysql@sha256:f030e84582d939d313fe2ef469b5c65ffd0f7dff3b4b98e6ec9ae2dccd83dcdf"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2018-05-04T23:41:21.907294662Z",
        "Container": "7fed895363c6e67ba9d52eaea107a1267d63e2d5ad46c567926d6897c7175624",
        "ContainerConfig": {
            "Hostname": "7fed895363c6",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "3306/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "GOSU_VERSION=1.7",
                "MYSQL_MAJOR=5.7",
                "MYSQL_VERSION=5.7.22-1debian9"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"mysqld\"]"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:71f4997ae44aead33eefe93100990253bca456f7b63dc5aad5baa936e7c14c46",
            "Volumes": {
                "/var/lib/mysql": {}
            },
            "WorkingDir": "",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": [],
            "Labels": {}
        },
        "DockerVersion": "17.06.2-ce",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "3306/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "GOSU_VERSION=1.7",
                "MYSQL_MAJOR=5.7",
                "MYSQL_VERSION=5.7.22-1debian9"
            ],
            "Cmd": [
                "mysqld"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:71f4997ae44aead33eefe93100990253bca456f7b63dc5aad5baa936e7c14c46",
            "Volumes": {
                "/var/lib/mysql": {}
            },
            "WorkingDir": "",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": [],
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 371961246,
        "VirtualSize": 371961246,
        "GraphDriver": {
            "Data": null,
            "Name": "aufs"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:d626a8ad97a1f9c1f2c4db3814751ada64f60aed927764a3f994fcd88363b659",
                "sha256:0fea3c8895d3871f5c577987f09735ae0889811efbad0dfde4d57851a4d40c00",
                "sha256:ed9fd767a1ff316e1a5896e150cede3ba2bcfe406d2135a6bc6306295cc479af",
                "sha256:f9dfc87a2e756c25245847a95ced53a6c065405b417d7635a28aa88235b30786",
                "sha256:5081cf9eb26642b5373aaa6eea7e16b6caefc3a495cf8fa0f296df48d8651f2f",
                "sha256:0404d129c384e4f45e5ae6a8d89c388a323bc0dda82ea45c6e4d0a442ea1e4b0",
                "sha256:98bb41f25d3307bc5c124529cfde7c3c27a0d612d918e91a36fc1e852e2e629c",
                "sha256:c11f67aad663de23cb77fbbbc6f7bee656e95e72cc820733aed6430a618738ab",
                "sha256:d2f1dc45f8bf45758eee7bc59fe94e9f251c415ef8d08540529d1a004772ee9e",
                "sha256:01df4e5c105921d20d800c1250c66009d472eb5628817bfa2c9523df5c53e03c",
                "sha256:4f840ea0733fe23b9fda79ff521a2e6e8112a615df5db064570502af19c08511"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

Ok, I just got it resolved.好的,我刚刚解决了。 Apparently, I forgot to create the DB and migrate the new changes.显然,我忘记创建数据库并迁移新更改。 Here's how I did it.这是我如何做到的。

  1. Removed nginx module.删除了nginx模块。 My worker (celery) and websocket_listener modules are okay to keep on restarting.我的工人(芹菜)和websocket_listener模块可以继续重新启动。 docker rm -f nginx
  2. Ran in detached mode.以分离模式运行。 docker-compose up -d mysql redis
  3. Used bash under mysql container.在mysql容器下使用bash。 docker exec -ti mysql bash
  4. Entered credentials (I have initially set them in mysql-init.txt , REF: https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html ) mysql -u root -p输入凭据(我最初将它们设置在mysql-init.txt ,REF: https : //dev.mysql.com/doc/refman/8.0/en/resetting-permissions.htmlmysql -u root -p
  5. Created DB.创建的数据库。 CREATE DATABASE bitpal;
  6. Imported a certain .sql file that was missing in my modules.导入了我的模块中缺少的某个 .sql 文件。
  7. Ran bitpal in detached mode.在分离模式下运行 bitpal。 docker-compose up -d bitpal
  8. Used bash under bitpal container.在 bitpal 容器下使用 bash。 docker exec -ti bitpal bash
  9. Migrations.迁移。 python manage.py migrate
  10. Used bash under mysql container.在mysql容器下使用bash。 docker exec -ti mysql bash
  11. Lastly, ran the sql under bitpal container.最后,在bitpal容器下运行sql。 mysql -u root -p bitpal < <.sql file>
  12. And it worked.它奏效了。

Here is the best option for the above issue.这是上述问题的最佳选择。 I did a lot of search for the same issue:我对同样的问题做了很多搜索:

sudo apt-get install --reinstall mariadb-server
sudo apt-get install --reinstall php-mysql

service mysql status

service mysql start

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM