Macosx下使用docker/mysql会出现什么问题
发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,这篇文章主要为大家展示了"Macosx下使用docker/mysql会出现什么问题",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"Macosx下使用dock
千家信息网最后更新 2026年11月03日Macosx下使用docker/mysql会出现什么问题
这篇文章主要为大家展示了"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启动脚本
#!/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命令,启动容器
以上是"Macosx下使用docker/mysql会出现什么问题"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!
问题
内容
篇文章
运行
容器
目录
脚本
学习
帮助
入口
命令
文件
方案
易懂
更多
权限
条理
知识
编带
行业
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网与科技
广州紫鲸互联网科技有限公司
国智互联网科技
深圳恒合互联网络科技有限公司
有马互联网科技
善班互联网科技
银优互联网科技有限公司
长亮科技互联网金融
深圳卡尔迅互联网科技有限公司怎么样
富国互联网科技创新基金
新华互联网科技2019
小米互联网科技园设置
现代互联网科技股
南山科技园互联网公司有哪些
天津腾达互联网科技有限公司
广州百诚互联网科技有限公司官网
全球科技与互联网公司市值变化
互联网科技职业技能培训学校
恒生科技指数 中概互联网
优雇互联网科技有限公司
精品咖啡豆
互联网科技企业
百单网互联网科技有限公司怎么样
卓越科技(互联网 )
安徽鑫晟辉互联网科技
百单互联网科技有限公司
中国航天科技大学国际工业互联网
晓花互联网科技有限公司网址
中国新注册互联网科技
保山浩联互联网科技有限公司