1.版本
1)操作系统
cat /etc/issue
Red Hat Enterprise Linux Server release 5.5 (Tikanga)
Kernel \r on an \m
cat /proc/version
Linux version 2.6.32-504.el6.x86_64 ([email protected]) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) ) #1 SMP Wed Oct 15 04:27:16 UTC 2014
2)mysql数据库版本
mysql --version
mysql Ver 14.14 Distrib 5.6.26, for linux-glibc2.5 (x86_64) using EditLine wrapper
2.问题描述
在创建一个新用户的时候报如下错误:
mysql> grant file on *.* to 'shao'@'%' identified by 'root'; ERROR 1054 (42S22): Unknown column 'plugin' in 'mysql.user'与此同时error log中记录了如下错误:
2015-12-11 14:46:11 13795 [Warning] Did not write failed 'grant file on *.* to 'shao'@'%' identified by 'root'' into binary log while granting/revoking privileges in databases.
mysql> grant file on *.* to 'shao'@'%' identified by 'root'; ERROR 1054 (42S22): Unknown column 'plugin' in 'mysql.user'##通过上面的报错我们可以看到,报的是plugin字段在mysql.user表中不存在,就是因为这个导致了我们添加用户报如上错误。那为什么mysql.user表中会缺少字段呢?(这种问题一般出现在通过mysql升级过程中)。我对比了一下另一套正常的数据库(5.6.26)发现mysql.user 有43个字段,而出现问题的数据库只有39个字段。
后来想起来是有一次为了恢复我一套5.1的数据时,把5.1的mysqldump备份文件拿到了这套库上来恢复了。去查了一下当前5.1版本的数据库的mysql.user果然是39个字段(对比每个字段同出问题的库是一致的)。那么现在问题就清楚了,因为现在库中使用的是5.1版本的mysql.user表。(那应该还有其他的系统表也是有问题的)
4.问题解决
居然问题清楚了,那解决问题就简单了,使用如下命令去修复表
mysql_upgrade --protocol=tcp -P3306 -p
修复完成后继续重启数据库实例,再次执行grant命令
mysql> grant file on *.* to 'shao'@'%' identified by 'root'; Query OK, 0 rows affected (0.04 sec) mysql>##命令执行成功