您的位置:首页 > 数据库 > SQL

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

2017-05-12 10:35 816 查看
http://blog.itpub.net/23249684/viewspace-1386707/

今早启动一台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库的操作权限,也要做好数据的备份。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐