这篇文章主要为大家展示了“Macosx下使用docker/mysql会出现什么问题”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Macosx下使用docker/mysql会出现什么问题”这篇文章吧。

问题描述

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

Creatingmysql_test-mysql_1Attachingtomysql_test-mysql_1test-mysql_1|Initializingdatabasetest-mysql_1|2016-03-23T04:32:37.437789Z0[Warning]Settinglower_case_table_names=2becausefilesystemfor/var/lib/mysql/iscaseinsensitivetest-mysql_1|2016-03-23T04:32:37.466955Z0[ERROR]InnoDB:Operatingsystemerrornumber13inafileoperation.test-mysql_1|2016-03-23T04:32:37.467828Z0[ERROR]InnoDB:Theerrormeansmysqlddoesnothavetheaccessrightstothedirectory.test-mysql_1|2016-03-23T04:32:37.468824Z0[ERROR]InnoDB:Operatingsystemerrornumber13inafileoperation.test-mysql_1|2016-03-23T04:32:37.468912Z0[ERROR]InnoDB:Theerrormeansmysqlddoesnothavetheaccessrightstothedirectory.test-mysql_1|2016-03-23T04:32:37.470280Z0[ERROR]InnoDB:Cannotopendatafile'./ibdata1'test-mysql_1|2016-03-23T04:32:37.470309Z0[ERROR]InnoDB:Couldnotopenorcreatethesystemtablespace.Ifyoutriedtoaddnewdatafilestothesystemtablespace,anditfailedhere,youshouldnoweditinnodb_data_file_pathinmy.cnfbacktowhatitwas,andremovethenewibdatafilesInnoDBcreatedinthisfailedattempt.InnoDBonlywrotethosefilesfullofzeros,butdidnotyetusetheminanyway.Butbecareful:donotremoveolddatafileswhichcontainyourpreciousdata!test-mysql_1|2016-03-23T04:32:37.470317Z0[ERROR]InnoDB:InnoDBDatabasecreationwasabortedwitherrorCannotopenafile.Youmayneedtodeletetheibdata1filebeforetryingtostartupagain.test-mysql_1|2016-03-23T04:32:38.073222Z0[ERROR]Plugin'InnoDB'initfunctionreturnederror.test-mysql_1|2016-03-23T04:32:38.073268Z0[ERROR]Plugin'InnoDB'registrationasaSTORAGEENGINEfailed.test-mysql_1|2016-03-23T04:32:38.073283Z0[ERROR]Failedtoinitializeplugins.test-mysql_1|2016-03-23T04:32:38.073289Z0[ERROR]Abortingtest-mysql_1|mysql_test-mysql_1exitedwithcode1

解决方案

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

#!/bin/bash#Fromhttps://github.com/docker-library/mysql/issues/99set-e#failonanyerrorecho'*WorkingaroundpermissionerrorsinDockeronMaclocallybymakingsurethat"mysql"usesthesameuidandgidasthehostvolume'TARGET_UID=$(stat-c"%u"/var/lib/mysql)echo'--Settingmysqlusertouseuid'$TARGET_UIDusermod-o-u$TARGET_UIDmysql||trueTARGET_GID=$(stat-c"%g"/var/lib/mysql)echo'--Settingmysqlgrouptousegid'$TARGET_GIDgroupmod-o-g$TARGET_GIDmysql||trueechoecho'*StartingMySQL'chown-Rmysql:root/var/run/mysqld//entrypoint.shmysqld--user=mysql--console

创建docker-compose.py,指定run-mysqld.sh脚本为容器入口

test-mysql:image:mysqlports:-"3306:3306"volumes:-/localhost/mysql/data:/var/lib/mysql-./scripts/run-mysqld.sh:/run-mysqld.shenvironment:-MYSQL_DATABASE=play-MYSQL_USER=play-MYSQL_PASSWORD=play-MYSQL_ROOT_PASSWORD=123456entrypoint:/run-mysqld.sh

运行docker-compose up命令,启动容器

以上是“Macosx下使用docker/mysql会出现什么问题”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!