问题原文
原帖链接 · Wolfgang Fahl · CC BY-SA 3.0
This error message shows up when I use ubuntu 16.04 and the latest mysql 5.7.19-0ubuntu0.16.04.1 in a Docker image.
What could be done to fix this?
To reproduce the error
Get the
Dockerfile:FROM ubuntu:16.04 RUN apt update RUN DEBIAN_FRONTEND=noninteractive apt install -y mysql-server(also available here)
Build and run:
docker build -t mysqlfail . docker run -it mysqlfail tail -1 /var/log/mysql/error.logwould have been shown the following error log:
2017-08-26T11:48:45.398445Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
Which was exactly what we wanted: a mysql with no root password set yet.
In the past (ubuntu 14.04 / mysql 5.5) a
service mysql startwas possible. Now if you try this it failsdocker run -it mysqlfail service mysql start * Starting MySQL database server mysqld No directory, logging in with HOME=/ [fail]and
/var/log/mysql/error.logcontains a line:2017-08-26T11:59:57.680618Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table storage engine for 'user' doesn't have this option
build log (for the complete Dockerfile)
Sending build context to Docker daemon 2.56kB
Step 1/4 : FROM ubuntu:16.04
---> ebcd9d4fca80
...
Step 4/4 : RUN service mysql start
---> Running in 5b899739d90d
* Starting MySQL database server mysqld
...fail!
The command '/bin/sh -c service mysql start' returned a non-zero code: 1
weird continuation
After experiments as outlined in my answer attempt, I created a shell script that does a
select count(*)
query on each table in the mysql space three times in a row (because experiments show that on some tables the query will fail exactly twice :-( ).
Then a
mysql_upgrade
and the
service mysql restart
is tried. In the Dockerfile the script is made available via
COPY mysqltest.sh .
The trials with this script give weird/crazy results.
For the
Docker environmentthe start still fails[ERROR] Fatal error: Can't open and lock privilege tables: Table storage engine for 'user' doesn't have this option
Running the script
sh mysqltest.sh rootin the
docker environmentleads to2017-08-27T09:12:47.021528Z 12 [ERROR] /usr/sbin/mysqld: Table './mysql/db' is marked as crashed and should be repaired
2017-08-27T09:12:47.050141Z 12 [ERROR] Couldn't repair table: mysql.db
2017-08-27T09:12:47.055925Z 13 [ERROR] /usr/sbin/mysqld: Table './mysql/db' is marked as crashed and should be repaired
2017-08-27T09:12:47.407700Z 54 [ERROR] /usr/sbin/mysqld: Table './mysql/proc' is marked as crashed and should be repaired
2017-08-27T09:12:47.433516Z 54 [ERROR] Couldn't repair table: mysql.proc
2017-08-27T09:12:47.440695Z 55 [ERROR] /usr/sbin/mysqld: Table './mysql/proc' is marked as crashed and should be repaired
2017-08-27T09:12:47.769485Z 81 [ERROR] /usr/sbin/mysqld: Table './mysql/tables_priv' is marked as crashed and should be repaired
2017-08-27T09:12:47.792061Z 81 [ERROR] Couldn't repair table: mysql.tables_priv
2017-08-27T09:12:47.798472Z 82 [ERROR] /usr/sbin/mysqld: Table './mysql/tables_priv' is marked as crashed and should be repaired
2017-08-27T09:12:47.893741Z 99 [ERROR] /usr/sbin/mysqld: Table './mysql/user' is marked as crashed and should be repaired
2017-08-27T09:12:47.914288Z 99 [ERROR] Couldn't repair table: mysql.user
2017-08-27T09:12:47.920459Z 100 [ERROR] /usr/sbin/mysqld: Table './mysql/user' is marked as crashed and should be repaired
What is going on here to cause this strange behavior?
已采纳解答
原帖链接 · Tibor Gyuris · CC BY-SA 3.0
Ran into the same problem today. I'm running the MySQL service during docker build for the unit tests and upgrading to MySQL CE 5.7.19 from MariaDB broke the build. What did solve the issue for me was running chown -R mysql:mysql /var/lib/mysql /var/run/mysqld each time before starting the mysql service.
So my Dockerfile looks like this now:
RUN chown -R mysql:mysql /var/lib/mysql /var/run/mysqld && \
service mysql start && \
mvn -q verify site
Hope this helps.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
