大网数据广告活动
服务器运维问答

Fatal error: Can't open and lock privilege tables: Table storage engine for 'user' doesn't have this option

· 52CE 我爱测

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 …

问题原文

原帖链接 · 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

  1. Get the Dockerfile:

    FROM ubuntu:16.04
    
    RUN apt update
    RUN DEBIAN_FRONTEND=noninteractive apt install -y mysql-server
    

    (also available here)

  2. Build and run:

    docker build -t mysqlfail . 
    docker run -it mysqlfail tail -1 /var/log/mysql/error.log
    

    would 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.

  3. In the past (ubuntu 14.04 / mysql 5.5) a service mysql start was possible. Now if you try this it fails

    docker run -it mysqlfail service mysql start
     * Starting MySQL database server mysqld    
      No directory, logging in with HOME=/  
                                                                            [fail]
    

    and /var/log/mysql/error.log contains 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.

  1. For the Docker environment the start still fails

    [ERROR] Fatal error: Can't open and lock privilege tables: Table storage engine for 'user' doesn't have this option

  2. Running the script

    sh mysqltest.sh root
    

    in the docker environment leads to

    2017-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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-08-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。