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

本篇文章给大家介绍关于macosx 下如何使用docker/mysql的问题,希望对大家有所帮助!

问题描述

在macosx下如果指定本地目录替换/var/lib/mysql,运行时会出现文件权限的错误,导致mysqld无法正常运行

Creating mysql_test-mysql_1Attaching to mysql_test-mysql_1test-mysql_1 | Initializing databasetest-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 insensitivetest-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] Abortingtest-mysql_1 | mysql_test-mysql_1 exited with code 1

解决方案

创建在scripts目录下mysqld启动脚本

AI建筑知识问答 AI建筑知识问答

用人工智能ChatGPT帮你解答所有建筑问题

AI建筑知识问答 22 查看详情 AI建筑知识问答

#!/bin/bash# From https://github.com/docker-library/mysql/issues/99set -e # fail on any errorecho '* 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_UIDusermod -o -u $TARGET_UID mysql || trueTARGET_GID=$(stat -c "%g" /var/lib/mysql)echo '-- Setting mysql group to use gid '$TARGET_GIDgroupmod -o -g $TARGET_GID mysql || trueechoecho '* 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的问题的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/288826.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫

关于作者

上一篇 2025年11月4日 19:42:48
下一篇 2025年11月4日 19:44:03

相关推荐

发表回复

登录后才能评论
关注微信