MySQL Fatal error: Can't open and lock privilege tables: Incorrect file format 'user'

前端 未结 3 1261
栀梦
栀梦 2020-12-16 01:27

MySQL (Percona 5.6) will not start.

This error has happened to me several times. Each time, I have had to remove MySQL data directories and reinstall MySQL.

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-16 01:54

    Here is the setup for @John Linhart's answer, if you're running Docker:

    First, start a new docker container with the appropriate tag from the mysql-container (the same you used to write the DB with).

    $ docker run --rm -it -v :/var/lib/mysql mysql: /bin/bash
    

    This will launch a new container with the correct named volume (or mounted volume) mounted in the container and drop you into a shell as root. The mysqld-Daemon will refuse to launch as root though, so we'll run it as the mysql-user:

    $ whoami
    root
    $ which mysqld
    /usr/sbin/mysqld
    $ su mysql
    $ whoami
    mysql
    $ /usr/sbin/mysqld --skip-grant-tables
    ....
    

    Now to run the SQL commands, we'll connect to the running container from a new terminal:

    $ docker ps 
    CONTAINER ID [...]
    abc123 [...]
    $ docker exec -it abc123 /bin/bash
    # We're on the container now!
    $ whoami
    root
    $ mysql
    ...
    

    And continue from there. When you're done, leave the container on the second terminal via exit. The terminal running mysqld will not respond to CMD+C, so we'll stop the container via Docker:

    $ docker ps
    CONTAINER ID [...]
    abc123 [...]
    $ docker stop abc123
    

提交回复
热议问题