登录  /  注册

分析Macosx下使用docker/mysql的问题

藏色散人
发布: 2021-11-25 14:49:17
转载
1672人浏览过

本篇文章给大家介绍关于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
登录后复制

解决方案

  • 创建在scripts目录下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
登录后复制
  • 运行docker-compose up命令,启动容器

推荐学习:《mysql视频教程

以上就是分析Macosx下使用docker/mysql的问题的详细内容,更多请关注php中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
相关标签:
来源:segmentfault网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
关于CSS思维导图的课件在哪? 课件
凡人来自于2024-04-16 10:10:18
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号