MySQL(Percona 5.6)将无法启动。
这个错误已经在我身上发生过好几次了。每次,我都必须删除 MySQL 数据目录并重新安装 MySQL。
还有其他方法修复 MySQL 吗? (特别是其中的数据没有被吹走?)
/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
我设法用 ruby.b 的 answer 解决了这个问题
你必须修复你的主机表。为此,请发出以下命令来绕过权限系统启动服务器
在一个终端中,运行
$ sudo mysqld --skip-grant-tables
打开另一个终端并执行这些命令
$ mysql
mysql> use mysql
mysql> repair table host use_frm;
mysql> exit
并重启mysql服务
$ sudo service mysql restart
感谢约翰让我走上了正确的道路,我的系统上还有一些其他的障碍需要克服。希望这对某人有帮助。
这是一个损坏的权限表。可能是由于升级或电源故障造成的。我的系统OpenSUSE 13.2,MySQL 5.6。简单的重新安装并不能解决问题,必须在重新安装之前删除 MySQL 的所有痕迹,否则……
关闭所有 MySQL 实例
$ systemctl stop mysql.service
$ pkill -9 mysqld
绕过权限系统启动服务器
$ sudo mysqld_safe --user=root --skip-grant-tables
启动MySQL命令行工具
$ mysql
如果您收到
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
mysqld_safe 正在其他地方使用其套接字运行。找到它。
$ sudo find / -type s
我的在/var/run/mysql/ 编辑 my.cnf 中的套接字行,记下现有的套接字设置。 我的线路变成了
socket=/var/run/mysql/mysql.sock
返回“关闭 MySQL 的所有实例”(这些说明的顶部)。按照他们的指示进行“启动 MySQL 命令行工具”。希望你能成功打开mysql。从 mysql 命令行。
mysql> use mysql
mysql> repair table user use_frm;
mysql> exit
关闭所有 MySQL 实例
$ systemctl stop mysql.service
$ pkill -9 mysqld
重新编辑 my.cnf,将套接字线恢复为原始设置。
我必须重置 mysql 数据目录中 2 个文件的权限。
$ chown mysql:mysql server2.err
$ chown mysql:mysql server2.pid
启动MySQL服务器
$ systemctl start mysql.service
然后我在另一个表(db)中遇到了相同的原始错误
[ERROR] Fatal error: Can't open and lock privilege tables: Incorrect file format 'db'
并且必须多次重复上述过程,更改“修复”命令,直到修复所有权限表。
mysql> repair table db use_frm;
这里是 @John Linhart 的答案的设置,如果你正在运行 Docker:
首先,使用
mysql
容器中的适当标签启动一个新的 docker 容器(与用于编写数据库的容器相同)。
$ docker run --rm -it -v <named_volume>:/var/lib/mysql mysql:<tag> /bin/bash
这将启动一个新容器,并在容器中安装正确命名的卷(或已安装的卷),并将您以 root 身份进入 shell。不过,
mysqld
-守护进程将拒绝以 root 身份启动,因此我们将以 mysql
-用户身份运行它:
$ whoami
root
$ which mysqld
/usr/sbin/mysqld
$ su mysql
$ whoami
mysql
$ /usr/sbin/mysqld --skip-grant-tables
....
现在要运行 SQL 命令,我们将从新终端连接到正在运行的容器:
$ docker ps
CONTAINER ID [...]
abc123 [...]
$ docker exec -it abc123 /bin/bash
# We're on the container now!
$ whoami
root
$ mysql
...
然后从那里继续。完成后,通过
exit
将容器留在第二个终端上。运行 mysqld
的终端不会响应 CMD+C,因此我们将通过 Docker 停止容器:
$ docker ps
CONTAINER ID [...]
abc123 [...]
$ docker stop abc123
要解决 Windows XAMPP 中的“致命错误:无法打开和锁定权限表:文件格式‘db’不正确”问题,请按照以下步骤操作:
C:\xampp\mysql\bin
,但根据您的安装情况可能会有所不同。C:\xampp\mysql\bin>mysqld.exe --skip-grant-tables
--skip-grant-tables 选项用于启动 MySQL 服务器而不加载授权表。授权表是 MySQL 存储有关用户权限信息的地方,例如哪些用户可以访问哪些数据库以及他们可以执行哪些操作
执行代码后,您可以在 xamp 中打开 mysql,它会自动激活。您可以在控制台中执行mysql代码。
mysql.exe
use mysql;
此命令选择存储用户权限的默认 MySQL 数据库。
repair table db use_frm;
此命令使用 .frm 文件修复“mysql”数据库中的“db”表。
exit;
您的 MySQL 权限现在应该已修复,并且您应该能够操作 XAMPP 而不会遇到错误。