MySQL5.7建立用户时报错

1 故障现象:
在建立用户时候,提示如下错误:

root@localhost Tue Oct 24 09:57:41 2017 09:57:41 [mysql]> create user 'liufofu'@'5.5.5.5' identified by 'liufofu'; html

ERROR 1805 (HY000): Column count of mysql.user is wrong. Expected 45, found 43. The table is probably corrupted
2 缘由分析
2.1 根据提示觉得是数据表出问题了,赶忙查查看,可是数据表能够正常查询
mysql

root@localhost Tue Oct 24 09:54:15 2017 09:54:15 [(none)]> select count(*) from mysql.user where user='liufofu' and host='5.5.5.5';
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.01 sec)
2.2 对数据表进行一次check table操做sql

root@localhost Tue Oct 24 09:57:50 2017 09:57:50 [mysql]> check table user;
+------------+-------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+------------+-------+----------+----------+
| mysql.user | check | status | OK |
+------------+-------+----------+----------+
1 row in set (0.00 sec)ide

2.3 进行了以上操做后,发现仍是不行。
跟使用人员进行沟通后,得出结果是:用户在建立时选择的是MySQL5.7的版本,而导入的备份文件为MySQL5.6的,版本不一致致使MySQL系统表有差别所以后。spa

3 解决方案
知道问题后,处理方案就很容易了,升级系统表便可。server

[ 09:59:27-root@liufofu:3311 ]#/usr/local/mysql-5.7.18/bin/mysql_upgrade -S /data/mysql/3311/mysql.sock
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv OK
mysql.db OK
mysql.engine_cost OK
mysql.event OK
mysql.func OK
mysql.general_log OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.slow_log OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
The sys schema is already up to date (version 1.5.1).
Found 0 sys functions, but expected 22. Re-installing the sys schema.
Upgrading the sys schema.
Checking databases.
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.htm

到此用户的问题获得了解决。文档

4 参考资料:it

4.1 mysql_upgrade官方文档
https://dev.mysql.com/doc/refman/5.7/en/mysql-upgrade.html
4.2 create user官方文档
MySQL5.7以前基本都是经过grant来建立用户,而从5.7开始建议使用create user来建立用户。
https://dev.mysql.com/doc/refman/5.7/en/create-user.htmlio

相关文章
相关标签/搜索