1. 程式人生 > >MySQL5.7創建用戶時報錯

MySQL5.7創建用戶時報錯

sel 使用 通過 complete general 溝通 stats http 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‘;

ERROR 1805 (HY000): Column count of mysql.user is wrong. Expected 45, found 43. The table is probably corrupted
2 原因分析
2.1 根據提示以為是數據表出問題了,趕緊查查看,但是數據表可以正常查詢

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操作

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)

2.3 進行了以上操作後,發現還是不行。
跟使用人員進行溝通後,得出結果是:用戶在創建時選擇的是MySQL5.7的版本,而導入的備份文件為MySQL5.6的,版本不一致導致MySQL系統表有差異所之後。

3 解決方案
知道問題後,處理方案就很容易了,升級系統表即可。

[ 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.

到此用戶的問題得到了解決。

4 參考資料:

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.html

MySQL5.7創建用戶時報錯