[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist 160913 0...

本文记录了一次MySQL服务启动过程中遇到的问题及解决过程。主要问题是由于缺失Perl模块导致的初始化失败和找不到mysql.user表引发的服务启动错误。通过安装必要的Perl模块并手动初始化MySQL系统表解决了这些问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2016-09-13 02:11:20 15424 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2016-09-13 02:11:20 15424 [Warning] InnoDB: New log files created, LSN=45782
2016-09-13 02:11:20 15424 [Note] InnoDB: Doublewrite buffer not found: creating new
2016-09-13 02:11:21 15424 [Note] InnoDB: Doublewrite buffer created
2016-09-13 02:11:21 15424 [Note] InnoDB: 128 rollback segment(s) are active.
2016-09-13 02:11:21 15424 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-09-13 02:11:21 15424 [Note] InnoDB: Foreign key constraint system tables created
2016-09-13 02:11:21 15424 [Note] InnoDB: Creating tablespace and datafile system tables.
2016-09-13 02:11:21 15424 [Note] InnoDB: Tablespace and datafile system tables created.
2016-09-13 02:11:21 15424 [Note] InnoDB: Waiting for purge to start
2016-09-13 02:11:21 15424 [Note] InnoDB: 5.6.31 started; log sequence number 0
2016-09-13 02:11:21 15424 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e4182e99-7978-11e6-aaf3-0606c1523531.
2016-09-13 02:11:21 15424 [Note] Server hostname (bind-address): '*'; port: 3306
2016-09-13 02:11:21 15424 [Note] IPv6 is available.
2016-09-13 02:11:21 15424 [Note]   - '::' resolves to '::';
2016-09-13 02:11:21 15424 [Note] Server socket created on IP: '::'.
2016-09-13 02:11:21 15424 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
160913 02:11:21 mysqld_safe mysqld from pid file /tmp/mysql.pid ended
2016-09-13 02:17:50 15652 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-09-13 02:17:50 15652 [Note] InnoDB: The InnoDB memory heap is disabled
2016-09-13 02:17:50 15652 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-09-13 02:17:50 15652 [Note] InnoDB: Memory barrier is not used
2016-09-13 02:17:50 15652 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-09-13 02:17:50 15652 [Note] InnoDB: Using CPU crc32 instructions
2016-09-13 02:17:50 15652 [Note] InnoDB: Initializing buffer pool, size = 1.0G
2016-09-13 02:17:50 15652 [Note] InnoDB: Completed initialization of buffer pool

前面说了内存那一关是过去了,但是又出现新的问题,说找不到表,,

这个原因就是你没初始化咯,明明我的脚本里面有初始化了啊,,为什么这里有说没有初始化呢???

不管了,那就手动初始化一下被

[root@ip-172-31-27-132 mysqldb]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb
FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:
Data::Dumper

哎哟。。。。原来是初始化出错了啊,怪不得脚本里面的初始化没有,这个不是什么问题,都提示你说少了Perl模块了,yum install就是了

yum install autoconf
#度娘说少了这个,我也不知道为啥

重新初始化一下

[root@ip-172-31-27-132 mysqldb]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb
Installing MySQL system tables...2016-09-13 02:17:50 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.31-log) starting as process 15652 ...
OK

Filling help tables...2016-09-13 02:17:52 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.31-log) starting as process 15676 ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
  /usr/local/mysql/bin/mysqladmin -u root -h 172.31.27.132 password 'new-password'

Alternatively you can run:

  /usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as /usr/local/mysql/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

OK,初始化是Ok了,那么在重启mysqld服务

[root@ip-172-31-27-132 mysqldb]# service mysqld start
Starting MySQL... SUCCESS! 

好啦,Mysql排错就到这里了额

 

### MySQL 'mysql.host' 表缺失问题解决方案 当遇到 `mysql.host` 表不存在的情况时,这通常意味着权限表结构损坏或者未正确初始化[^1]。以下是针对此问题的具体分析和解决方法: #### 1. 数据库元数据损坏的可能性 MySQL 的权限管理依赖于一系列存储在 `mysql` 系统数据库中的表,例如 `user`, `db`, 和 `host` 等。如果这些表之一丢失或被删除,则可能导致错误消息 “cannot open and lock privilege tables”。这种问题可能由以下原因引起: - 手动操作失误导致系统表被意外删除。 - 升级过程中发生异常中断。 #### 2. 解决方案概述 为了恢复正常的权限功能,可以按照如下方式处理: ##### (a) 备份现有数据 无论采取何种修复措施,在执行任何更改之前都应备份当前的 `mysql` 数据库内容以防止进一步的数据损失[^2]: ```sql mysqldump mysql > mysql_backup.sql ``` ##### (b) 使用 mysqld --initialize 初始化新实例 对于全新安装环境下的情况,可以通过重新初始化来创建默认的系统架构文件夹以及必要的配置项。注意该命令会清除已有账户设置,请谨慎使用[^3]: ```bash mysqld --initialize-insecure --user=mysql ``` ##### (c) 运行 mysql_install_db 脚本重建基础框架 另一种更安全的方法是利用官方提供的工具脚本来重置缺少的部分而不影响其他正常工作的组件: ```bash mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql ``` 上述指令适用于大多数 Linux 发行版;具体路径需依据实际部署情况进行调整[^4]。 ##### (d) 更新至最新版本并应用升级补丁程序 如果是由于软件更新不完全引发的问题,则建议先确认所使用的 MySQL 版本号,并下载对应平台上的正式发行包完成替换工作后再尝试启动服务进程[^5]。 #### 3. 验证修复效果 成功实施以上任一策略之后,重启服务器验证是否恢复正常运作状态: ```bash service mysql restart ``` 接着登录到控制台测试能否顺利访问受保护资源区域内的对象实体。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值