>  기사  >  데이터 베이스  >  Macosx에서 docker/mysql을 사용한 문제 분석

Macosx에서 docker/mysql을 사용한 문제 분석

藏色散人
藏色散人앞으로
2021-11-25 14:49:171843검색

이 기사는 Macosx에서 docker/mysql을 사용하는 방법을 소개합니다. 도움이 되길 바랍니다!

문제 설명

macosx에서 /var/lib/mysql을 대체할 로컬 디렉터리를 지정하면 런타임 중에 파일 권한 오류가 발생하여 mysqld가 정상적으로 실행되지 않습니다

Creating mysql_test-mysql_1
Attaching to mysql_test-mysql_1
test-mysql_1 | Initializing database
test-mysql_1 | 2016-03-23T04:32:37.437789Z 0 [Warning] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
test-mysql_1 | 2016-03-23T04:32:37.466955Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
test-mysql_1 | 2016-03-23T04:32:37.467828Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
test-mysql_1 | 2016-03-23T04:32:37.468824Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
test-mysql_1 | 2016-03-23T04:32:37.468912Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
test-mysql_1 | 2016-03-23T04:32:37.470280Z 0 [ERROR] InnoDB: Cannot open datafile './ibdata1'
test-mysql_1 | 2016-03-23T04:32:37.470309Z 0 [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!
test-mysql_1 | 2016-03-23T04:32:37.470317Z 0 [ERROR] InnoDB: InnoDB Database creation was aborted with error Cannot open a file. You may need to delete the ibdata1 file before trying to start up again.
test-mysql_1 | 2016-03-23T04:32:38.073222Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
test-mysql_1 | 2016-03-23T04:32:38.073268Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
test-mysql_1 | 2016-03-23T04:32:38.073283Z 0 [ERROR] Failed to initialize plugins.
test-mysql_1 | 2016-03-23T04:32:38.073289Z 0 [ERROR] Aborting
test-mysql_1 | 
mysql_test-mysql_1 exited with code 1

해결 방법

  • Creation 스크립트 디렉터리에 mysqld 시작 스크립트

#!/bin/bash
# From https://github.com/docker-library/mysql/issues/99
set -e # fail on any error

echo '* Working around permission errors in Docker on Mac locally by making sure that "mysql" uses the same uid and gid as the host volume'
TARGET_UID=$(stat -c "%u" /var/lib/mysql)
echo '-- Setting mysql user to use uid '$TARGET_UID
usermod -o -u $TARGET_UID mysql || true
TARGET_GID=$(stat -c "%g" /var/lib/mysql)
echo '-- Setting mysql group to use gid '$TARGET_GID
groupmod -o -g $TARGET_GID mysql || true
echo
echo '* Starting MySQL'
chown -R mysql:root /var/run/mysqld/
/entrypoint.sh mysqld --user=mysql --console
  • 를 생성하고 docker-compose.py를 생성하고 run-mysqld.sh 스크립트를 컨테이너 항목

test-mysql:
    image: mysql 
    ports:
        - "3306:3306"
    volumes:   
        - /localhost/mysql/data:/var/lib/mysql 
        - ./scripts/run-mysqld.sh:/run-mysqld.sh
    environment:
        - MYSQL_DATABASE=play
        - MYSQL_USER=play
        - MYSQL_PASSWORD=play
        - MYSQL_ROOT_PASSWORD=123456
    entrypoint: /run-mysqld.sh
  • 으로 지정합니다. 컨테이너를 시작하는 명령 작성

추천 학습: "mysql 비디오 튜토리얼"

위 내용은 Macosx에서 docker/mysql을 사용한 문제 분석의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 segmentfault.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제