Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

今早启动一台mysql测试库的时候,启动失败:
[root@test11g scripts]# /etc/init.d/mysqld restart
Shutting down MySQL..                                      [  OK  ]
Starting MySQL..The server quit without updating PID file ([FAILED]ql/data/test11g.pid).

检查错误日志发现如下信息:
2015-01-01 09:43:42 6983 [Note] Server socket created on IP: '::'.
2015-01-01 09:43:42 6983 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
150101 09:43:42 mysqld_safe mysqld from pid file /tol/mysql/data/test11g.pid ended

错误信息可以看出来,是mysql.user表有问题,导致mysql服务启动失败

进入到mysql的data目录,查看该表的文件是否存在,以及权限是否正确:
[root@test11g mysql]# pwd
/tol/mysql/data/mysql

[root@test11g mysql]# ls user.*
ls: cannot access user.*: No such file or directory

发现user表没有了,不知道是被人为drop了,还是被rm了,由于是测试库,普通用户的权限都给的很大,有对mysql库的操作权限,
先尝试用mysql_install_db脚本初始化一下数据,试着恢复一下:
[root@test11g scripts]# ./mysql_install_db --defaults-file=/etc/my.cnf  --user=mysql --basedir=/tol/mysql --datadir=/tol/mysql/data
Installing MySQL system tables...OK
Filling help tables...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:
  /tol/mysql/bin/mysqladmin -u root password 'new-password'
  /tol/mysql/bin/mysqladmin -u root -h test11g password 'new-password'
Alternatively you can run:
  /tol/mysqlbin/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 . ; /tol/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
WARNING: Found existing config file /tol/mysql/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /tol/mysql/my-new.cnf,
please compare it with your file and take the changes you need.
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

[root@test11g scripts]# /etc/init.d/mysqld start  
Starting MySQL..                                           [  OK  ]

初始化完成后,mysql能正常启动了,后续再设置一下root的密码,把普通用户手工创建一下,基本就可以用了。
如果是外网数据库,一定不要分配给普通用户对mysql库的操作权限,也要做好数据的备份。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23249684/viewspace-1386707/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23249684/viewspace-1386707/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值