MySQL数据挂载到主机出错?
如果不挂载主机,则运行成功,挂载执行命令如下所示:
docker run -d -p 3306:3306 -v /data:/var/lib/mysql image
执行后,在/data中会出现如下文件列表:
93a2e8e96e0a.err ibdata1 ib_logfile0 ib_logfile1
其中93*.err内容如下起所示:
151125 07:54:25 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Warning: World-writable config file '/etc/mysql/my.cnf' is ignored
151125 7:54:25 Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist
151125 7:54:25 Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
151125 7:54:25 InnoDB: The InnoDB memory heap is disabled
151125 7:54:25 InnoDB: Mutexes and rw_locks use GCC atomic builtins
151125 7:54:25 InnoDB: Compressed tables use zlib 1.2.8
151125 7:54:25 InnoDB: Using Linux native AIO
151125 7:54:25 InnoDB: Initializing buffer pool, size = 128.0M
151125 7:54:25 InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
151125 7:54:25 InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
151125 7:54:25 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
151125 7:54:25 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: 127 rollback segment(s) active.
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
151125 7:54:25 InnoDB: Waiting for the background threads to start
151125 7:54:26 InnoDB: 5.5.35 started; log sequence number 0
151125 7:54:26 Server hostname (bind-address): '0.0.0.0'; port: 3306
151125 7:54:26 - '0.0.0.0' resolves to '0.0.0.0';
151125 7:54:26 Server socket created on IP: '0.0.0.0'.
151125 7:54:26 Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
151125 07:54:26 mysqld_safe mysqld from pid file /var/lib/mysql/93a2e8e96e0a.pid ended
8 个回复
robott - 85后码农
赞同来自:
这个跟挂载没关系,挂载用数据卷命令-v就完了,你这个属于image有问题,重新pull吧。
hsh075623201
赞同来自:
但是我 不用-v 命令的时候, mysql 能够启动的。。。
devopsify - DevOps Evangelist
赞同来自:
你这个image是官方的还是自己做得?/var/lib/mysql在container里存在么?你这个还想是mysql没起来,也有可能是mysql没有权限访问host上mount的volume,结果导致mysql start failure.
hsh075623201
赞同来自:
@devopsify 你好 , images 是自己做的, /var/lib/mysql在container存在的,并且里面一些生成的文件也同步到/data了 。而且我host上/data文件都改成777了。
image dockerfile:
<pre>FROM ubuntu
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get -y upgrade
RUN apt-get install -y mysql-server
RUN service mysql start &&\
mysql -e "grant all privileges on <span>.<span> to 'root'@'%' identified by 'root';" &&\
mysql -e "grant all privileges on <span>.<span> to 'root'@'localhost' identified by 'root';" &&\
mysql -u root -proot -e "show databases;"
ADD my.cnf /etc/mysql/my.cnf
ADD start.sh ./start.sh
RUN chmod +x ./start.sh
EXPOSE 3306
CMD </pre>
devopsify - DevOps Evangelist
赞同来自:
不知道你start.sh里面内容,还有你不应该run apt-get upgrade
devopsify - DevOps Evangelist
赞同来自:
看了一下你docker olé,完全不对啊,mysql怎么被service run起来了
hsh075623201
赞同来自:
@devopsify 哦 这样不行的啊 好吧 那我再改改 谢谢指导!
baozilala
赞同来自:
docker run -it -d -p 80:80 -v /Users/xxx/Docker/lamp/data/mysql:/var/lib/mysql -v /Users/xxx/Docker/lamp/www:/var/www/html 293ef2f50d98
我到是用 -v 方式挂载的,可结果是导致无法运行Mysql,错误代码如下:
Starting MySQL database server: mysqld . . . . . . . . . . . . . . . . . . . . . . . . . . . .[FAI failed!
尝试着连接mysql -uroot -p 却出现了如下错误:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
同时检查了 /var/lib/mysq l的权限:
drwxrwxrwx 6 root root 204 Jul 11 03:11 mysql
如果不加载此文件夹时候能正常运行,而且看到/var/lib/mysql 文件夹下有一些文件,如 mysql 文件.
但是一使用 -v 加载host目录到/var/lib/mysql的时候,从Host查看这个Mysql文件夹,却是空的.
service mysql start的时候,mysql文件夹会生成3个log 文档.
ib_logfile0 - 5.2
ib_logfile1 - 5.2
ibdata1 - 18.9
请问下,这是什么情况呢? 已经做了很多功课了,可就是找不到解决办法.