[英]MySQL Fatal error: Can't open and lock privilege tables: Incorrect file format 'user'
MySQL (Percona 5.6) will not start. MySQL(Percona 5.6)无法启动。
This error has happened to me several times. 这个错误发生在我身上好几次。 Each time, I have had to remove MySQL data directories and reinstall MySQL.
每次,我都必须删除MySQL数据目录并重新安装MySQL。
Is there another way to fix MySQL? 还有另一种修复MySQL的方法吗? (Specifically one in which the data not blown away?)
(特别是没有吹走数据的那个?)
/var/log/mysql/error.log /var/log/mysql/error.log
150214 16:36:39 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2015-02-14 16:36:40 0 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
2015-02-14 16:36:40 0 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2015-02-14 16:36:40 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-02-14 16:36:40 1018 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
2015-02-14 16:36:40 1018 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Incorrect file format 'plugin'
2015-02-14 16:36:40 1018 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2015-02-14 16:36:40 1018 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-02-14 16:36:40 1018 [Note] InnoDB: The InnoDB memory heap is disabled
2015-02-14 16:36:40 1018 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-02-14 16:36:40 1018 [Note] InnoDB: Memory barrier is not used
2015-02-14 16:36:40 1018 [Note] InnoDB: Compressed tables use zlib 1.2.8
2015-02-14 16:36:40 1018 [Note] InnoDB: Using Linux native AIO
2015-02-14 16:36:40 1018 [Note] InnoDB: Using CPU crc32 instructions
2015-02-14 16:36:40 1018 [Note] InnoDB: Initializing buffer pool, size = 256.0M
2015-02-14 16:36:40 1018 [Note] InnoDB: Completed initialization of buffer pool
2015-02-14 16:36:40 1018 [Note] InnoDB: Highest supported file format is Barracuda.
2015-02-14 16:36:40 1018 [Note] InnoDB: The log sequence numbers 714340126 and 714340126 in ibdata files do not match the log sequence number 716513090 in the ib_logfiles!
2015-02-14 16:36:40 1018 [Note] InnoDB: Database was not shutdown normally!
2015-02-14 16:36:40 1018 [Note] InnoDB: Starting crash recovery.
2015-02-14 16:36:40 1018 [Note] InnoDB: Reading tablespace information from the .ibd files...
2015-02-14 16:36:40 1018 [Note] InnoDB: Restoring possible half-written data pages
2015-02-14 16:36:40 1018 [Note] InnoDB: from the doublewrite buffer...
InnoDB: Last MySQL binlog file position 0 292596, file name binlog.000056
2015-02-14 16:36:40 1018 [Note] InnoDB: 128 rollback segment(s) are active.
2015-02-14 16:36:40 1018 [Note] InnoDB: Waiting for purge to start
2015-02-14 16:36:40 1018 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.6.21-70.1 started; log sequence number 716513090
2015-02-14 16:36:40 1018 [Note] Recovering after a crash using binlog
2015-02-14 16:36:40 1018 [Note] Starting crash recovery...
2015-02-14 16:36:40 1018 [Note] Crash recovery finished.
2015-02-14 16:36:40 1018 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work.
2015-02-14 16:36:40 1018 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
2015-02-14 16:36:40 1018 [Note] Server hostname (bind-address): '*'; port: 3306
2015-02-14 16:36:40 1018 [Note] IPv6 is available.
2015-02-14 16:36:40 1018 [Note] - '::' resolves to '::';
2015-02-14 16:36:40 1018 [Note] Server socket created on IP: '::'.
2015-02-14 16:36:40 1018 [ERROR] Fatal error: Can't open and lock privilege tables: Incorrect file format 'user'
150214 16:36:40 mysqld_safe mysqld from pid file /tmp/mysqld.pid ended
I managed so solve this problem with answer from ruby.b 我管理所以从ruby.b回答这个问题
You'll have to repair your host table.
你必须修复主机表。 To do this, issue the following command to start your server bypassing the privilege system
为此,请发出以下命令以启动服务器绕过权限系统
In one terminal, run 在一个终端,运行
$ sudo mysqld --skip-grant-tables
Open another terminal and execute these commands 打开另一个终端并执行这些命令
$ mysql
mysql> use mysql
mysql> repair table host use_frm;
mysql> exit
And restart the mysql service 并重启mysql服务
$ sudo service mysql restart
Thanks to John for putting me on the right track, I had a few other hoops to jump through on my system. 感谢约翰让我走上了正确的轨道,我还有一些其他的箍要跳过我的系统。 Hope this helps someone.
希望这有助于某人。
This is a corrupt privilege table. 这是一个损坏的权限表。 Maybe caused by an upgrade or power failure.
可能是由升级或电源故障引起的。 My system OpenSUSE 13.2, MySQL 5.6.
我的系统是OpenSUSE 13.2,MySQL 5.6。 Simple reinstall does not fix, must delete all traces of MySQL before reinstall OR…
简单的重新安装不修复,必须删除所有MySQL的痕迹,然后重新安装OR ...
Close down all instances of MySQL 关闭所有MySQL实例
$ systemctl stop mysql.service
$ pkill -9 mysqld
Start server bypassing privilege system 启动服务器绕过权限系统
$ sudo mysqld_safe --user=root --skip-grant-tables
Start MySQL command line tool 启动MySQL命令行工具
$ mysql
If you receive 如果你收到
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
mysqld_safe is running with its socket somewhere else. mysqld_safe正在其他地方运行其套接字。 Find it with.
找到它。
$ sudo find / -type s
Mine was in /var/run/mysql/ Edit the socket line in my.cnf, making a note of your existing socket setting. 我在/ var / run / mysql /编辑my.cnf中的套接字行,记下你现有的套接字设置。 My line became
我的路线变了
socket=/var/run/mysql/mysql.sock
Return to 'Close down all instances of MySQL' (the top of these instructions). 返回'关闭所有MySQL实例'(这些指令的顶部)。 Follow them through to 'Start MySQL command line tool'.
按照它们“启动MySQL命令行工具”进行操作。 Hopefully you can open mysql successfully.
希望你能成功打开mysql。 From mysql command line.
从mysql命令行。
mysql> use mysql
mysql> repair table user use_frm;
mysql> exit
Close down all instances of MySQL 关闭所有MySQL实例
$ systemctl stop mysql.service
$ pkill -9 mysqld
Re-edit my.cnf, returning the socket line to its original setting. 重新编辑my.cnf,将套接字行恢复为原始设置。
I had to reset permissions on 2 files in my mysql data directory. 我不得不重置我的mysql数据目录中的2个文件的权限。
$ chown mysql:mysql server2.err
$ chown mysql:mysql server2.pid
Start the MySQL server 启动MySQL服务器
$ systemctl start mysql.service
I then got the same original error with another table (db) 然后,我与另一个表(db)得到相同的原始错误
[ERROR] Fatal error: Can't open and lock privilege tables: Incorrect file format 'db'
And had to repeat the above procedure multiple times altering the 'repair' command until all privilege tables were fixed. 并且必须多次重复上述过程以修改'repair'命令,直到修复所有权限表。
mysql> repair table db use_frm;
Here is the setup for @John Linhart 's answer, if you're running Docker : 如果您正在运行Docker ,这是@John Linhart的答案的设置:
First, start a new docker container with the appropriate tag from the mysql
-container (the same you used to write the DB with). 首先,使用
mysql
-container中的相应标记启动一个新的docker容器(与用于编写数据库时相同)。
$ docker run --rm -it -v <named_volume>:/var/lib/mysql mysql:<tag> /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. 这将启动一个新容器,其中包含安装在容器中的正确命名卷(或已安装的卷),并以root身份将您放入shell中。 The
mysqld
-Daemon will refuse to launch as root though, so we'll run it as the mysql
-user: mysqld
-Daemon将拒绝以root用户身份启动,因此我们将以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: 现在要运行SQL命令,我们将从新终端连接到正在运行的容器:
$ 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
. 完成后,通过
exit
将容器放在第二个终端上。 The terminal running mysqld
will not respond to CMD+C, so we'll stop the container via Docker: 运行
mysqld
的终端不会响应CMD + C,所以我们将通过Docker停止容器:
$ docker ps
CONTAINER ID [...]
abc123 [...]
$ docker stop abc123
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.