简体   繁体   English

如何修复mysql.user表?

[英]How to repair mysql.user table?

I am starting mysql-5.6 server with mysql-5.5 data. 我正在使用mysql-5.5数据启动mysql-5.6服务器。 I am getting the following error. 我收到以下错误。 I can't start server for running mysql_upgrade Error: 我无法启动服务器来运行mysql_upgrade错误:

2016-06-14 11:07:54 5827 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-06-14 11:07:54 5827 [Note] InnoDB: The InnoDB memory heap is disabled
2016-06-14 11:07:54 5827 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-06-14 11:07:54 5827 [Note] InnoDB: Memory barrier is not used
2016-06-14 11:07:54 5827 [Note] InnoDB: Compressed tables use zlib 1.2.8
2016-06-14 11:07:54 5827 [Note] InnoDB: Using Linux native AIO
2016-06-14 11:07:54 5827 [Note] InnoDB: Using CPU crc32 instructions
2016-06-14 11:07:54 5827 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-06-14 11:07:54 5827 [Note] InnoDB: Completed initialization of buffer pool
2016-06-14 11:07:54 5827 [Note] InnoDB: Highest supported file format is Barracuda.
2016-06-14 11:07:54 5827 [Note] InnoDB: 128 rollback segment(s) are active.
2016-06-14 11:07:54 5827 [Note] InnoDB: Waiting for purge to start
2016-06-14 11:07:54 5827 [Note] InnoDB: 5.6.30 started; log sequence number 1600607
2016-06-14 11:07:54 5827 [Note] Server hostname (bind-address): '*'; port: 3306
2016-06-14 11:07:54 5827 [Note] IPv6 is available.
2016-06-14 11:07:54 5827 [Note]   - '::' resolves to '::';
2016-06-14 11:07:54 5827 [Note] Server socket created on IP: '::'.
2016-06-14 11:07:54 5827 [ERROR] Fatal error: Can't open and lock privilege tables: Incorrect key file for table 'user'; try to repair it
160614 11:07:54 mysqld_safe mysqld from pid file   /var/run/mysqld/mysqld.pid ended

Started with --skip-grant-tables 以--skip-grant-tables开头

mysqld --skip-grant-tables &
[1] 6534
root@1428a7d90520:/var/lib/mysql# 2016-06-14 11:16:17 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.
2016-06-14 11:16:17 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-06-14 11:16:17 0 [Note] mysqld (mysqld 5.6.30-0ubuntu0.14.04.1) starting as process 6534 ...
2016-06-14 11:16:18 6534 [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.
2016-06-14 11:16:18 6534 [Note] Plugin 'FEDERATED' is disabled.
2016-06-14 11:16:18 6534 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-06-14 11:16:18 6534 [Note] InnoDB: The InnoDB memory heap is disabled
2016-06-14 11:16:18 6534 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-06-14 11:16:18 6534 [Note] InnoDB: Memory barrier is not used
2016-06-14 11:16:18 6534 [Note] InnoDB: Compressed tables use zlib 1.2.8
2016-06-14 11:16:18 6534 [Note] InnoDB: Using Linux native AIO
2016-06-14 11:16:18 6534 [Note] InnoDB: Using CPU crc32 instructions
2016-06-14 11:16:21 6534 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-06-14 11:16:21 6534 [Note] InnoDB: Completed initialization of buffer pool
2016-06-14 11:16:21 6534 [Note] InnoDB: Highest supported file format is Barracuda.
2016-06-14 11:16:21 6534 [Note] InnoDB: 128 rollback segment(s) are active.
2016-06-14 11:16:21 6534 [Note] InnoDB: Waiting for purge to start
2016-06-14 11:16:21 6534 [Note] InnoDB: 5.6.30 started; log sequence number 1600617
2016-06-14 11:16:21 6534 [Note] Server hostname (bind-address): '*'; port: 3306
2016-06-14 11:16:21 6534 [Note] IPv6 is available.
2016-06-14 11:16:21 6534 [Note]   - '::' resolves to '::';
2016-06-14 11:16:21 6534 [Note] Server socket created on IP: '::'.
2016-06-14 11:16:21 6534 [Note] mysqld: ready for connections.
Version: '5.6.30-0ubuntu0.14.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)

root@1428a7d90520:/var/lib/mysql# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.30-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>  select TABLE_NAME,ENGINE from information_schema.tables where TABLE_SCHEMA='mysql';
+---------------------------+--------+
| TABLE_NAME                | ENGINE |
+---------------------------+--------+
| columns_priv              | MyISAM |
| db                        | MyISAM |
| event                     | MyISAM |
| func                      | MyISAM |
| general_log               | CSV    |
| help_category             | MyISAM |
| help_keyword              | MyISAM |
| help_relation             | MyISAM |
| help_topic                | MyISAM |
| innodb_index_stats        | InnoDB |
| innodb_table_stats        | InnoDB |
| ndb_binlog_index          | MyISAM |
| plugin                    | MyISAM |
| proc                      | MyISAM |
| procs_priv                | MyISAM |
| proxies_priv              | MyISAM |
| servers                   | MyISAM |
| slave_master_info         | InnoDB |
| slave_relay_log_info      | InnoDB |
| slave_worker_info         | InnoDB |
| slow_log                  | CSV    |
| tables_priv               | MyISAM |
| time_zone                 | MyISAM |
| time_zone_leap_second     | MyISAM |
| time_zone_name            | MyISAM |
| time_zone_transition      | MyISAM |
| time_zone_transition_type | MyISAM |
| user                      | MyISAM |
+---------------------------+--------+
28 rows in set (0.50 sec)

mysql> repair table  mysql.user;
+------------+--------+----------+-------------------------------------------------------+
| Table      | Op     | Msg_type | Msg_text                                              |
+------------+--------+----------+-------------------------------------------------------+
| mysql.user | repair | Error    | Incorrect key file for table 'user'; try to repair it |
| mysql.user | repair | error    | Corrupt                                               |
+------------+--------+----------+-------------------------------------------------------+
2 rows in set (0.00 sec)

How can i repair that table? 我该如何修理那张桌子? I tried this but i lost my data in user table. 我尝试了此操作,但丢失了用户表中的数据。

mysql> repair table  mysql.user USE_FRM;
+------------+--------+----------+--------------------------------------------------+
| Table      | Op     | Msg_type | Msg_text                                         |
+------------+--------+----------+--------------------------------------------------+
| mysql.user | repair | info     | Key 1 - Found wrong stored record at 0           |
| mysql.user | repair | info     | Found block that points outside data file at 184 |
| mysql.user | repair | info     | Found block that points outside data file at 292 |
| mysql.user | repair | info     | Found block that points outside data file at 296 |
| mysql.user | repair | info     | Found block that points outside data file at 300 |
| mysql.user | repair | info     | Found block that points outside data file at 304 |
| mysql.user | repair | info     | Found block that points outside data file at 308 |
| mysql.user | repair | info     | Found block that points outside data file at 312 |
| mysql.user | repair | info     | Found block that points outside data file at 316 |
| mysql.user | repair | info     | Found block that points outside data file at 340 |
| mysql.user | repair | info     | Found block that points outside data file at 392 |
| mysql.user | repair | info     | Found block that points outside data file at 396 |
| mysql.user | repair | info     | Found block that points outside data file at 400 |
| mysql.user | repair | info     | Found block that points outside data file at 404 |
| mysql.user | repair | info     | Found block that points outside data file at 408 |
| mysql.user | repair | info     | Found block that points outside data file at 412 |
| mysql.user | repair | info     | Found block that points outside data file at 416 |
| mysql.user | repair | info     | Found block that points outside data file at 420 |
| mysql.user | repair | info     | Found block that points outside data file at 448 |
| mysql.user | repair | info     | Found block that points outside data file at 452 |
| mysql.user | repair | info     | Found block that points outside data file at 456 |
| mysql.user | repair | info     | Found block that points outside data file at 460 |
| mysql.user | repair | info     | Found block that points outside data file at 464 |
| mysql.user | repair | info     | Found block that points outside data file at 468 |
| mysql.user | repair | info     | Found block that points outside data file at 472 |
| mysql.user | repair | info     | Found block that points outside data file at 500 |
| mysql.user | repair | info     | Found block that points outside data file at 504 |
| mysql.user | repair | info     | Found block that points outside data file at 508 |
| mysql.user | repair | info     | Found block that points outside data file at 512 |
| mysql.user | repair | info     | Found block that points outside data file at 516 |
| mysql.user | repair | info     | Found block that points outside data file at 520 |
| mysql.user | repair | info     | Found block that points outside data file at 524 |
| mysql.user | repair | info     | Found block that points outside data file at 528 |
| mysql.user | repair | info     | Found block that points outside data file at 556 |
| mysql.user | repair | info     | Found block that points outside data file at 560 |
| mysql.user | repair | info     | Found block that points outside data file at 564 |
| mysql.user | repair | info     | Found block that points outside data file at 568 |
| mysql.user | repair | info     | Found block that points outside data file at 572 |
| mysql.user | repair | info     | Found block that points outside data file at 576 |
| mysql.user | repair | info     | Found block that points outside data file at 580 |
| mysql.user | repair | info     | Found block that points outside data file at 604 |
| mysql.user | repair | info     | Found block that points outside data file at 608 |
| mysql.user | repair | info     | Found block that points outside data file at 612 |
| mysql.user | repair | info     | Found block that points outside data file at 616 |
| mysql.user | repair | info     | Found block that points outside data file at 620 |
| mysql.user | repair | info     | Found block that points outside data file at 624 |
| mysql.user | repair | info     | Found block that points outside data file at 628 |
| mysql.user | repair | info     | Found block that points outside data file at 632 |
| mysql.user | repair | status   | OK                                               |
+------------+--------+----------+--------------------------------------------------+
49 rows in set (0.03 sec)


mysql> select * from mysql.user;
Empty set (0.01 sec)

Issue got resolved now. 问题已解决。 Each MYISAM table has 3 files in data directory. 每个MYISAM表在数据目录中都有3个文件。

For user table, 对于用户表,

  1. user.frm - Table metadata user.frm-表元数据
  2. user.MYI - Index user.MYI-索引
  3. user.MYD - Data user.MYD-数据

I missed overwriting user.frm file (Because of taking docker rw changes). 我错过了覆盖user.frm文件(因为要进行docker rw更改)。 So user.frm is from mysql-5.6 and user.MYI, user.MYD from mysql-5.5. 因此,user.frm来自mysql-5.6,而user.MYI来自mysql-5.5。 password_expired column was added mysql user table in 5.6. password_expired列在5.6中添加了mysql用户表。 Because of incompatibility with user.frm and other files it was non-recoverable. 由于与user.frm和其他文件不兼容,因此无法恢复。 I tried copying user.frm from mysql-5.5 and its working. 我尝试从mysql-5.5复制user.frm及其工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM