今天用mysql创建用户时,出现了创建完成后的用户无法登录,授权无效的情况
CREATE USER testIDENTIFIED BY 'test';
mysql> GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'test'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
查看用户表的情况如下:
再次进行授权时:
mysql> GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'test'@'%';
ERROR 1524 (HY000): Plugin '*E3619321C1A937C46A0D8BD1DAC39F93B27D4458' is not loaded
这是因为mysql.user表中对应的plugin不对,默认应该为mysql_native_password才对,于是更改成mysql_native_password
update mysql.user set plugin='mysql_native_password', password=PASSWORD('test') where User='test';
现在mysql.user表中对应的用户信息正常了
再次执行:
mysql> GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'test'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
SQL语句正常执行,再次查看mysql.user表的情况
不起作用?
重启mysql数据库,还是不对,删除掉用户再次创建,问题一样,所以从mysql库本身去排查问题。
于是先进行数据库升级:
./mysql_upgrade -h127.0.0.1 -uroot -p'xxxx' --force
mysql_upgrade: [Warning] Using a password on the command line interface can be insecure.
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.ha_health_check 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.rds_table_checksums 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
Upgrading the sys schema.
Checking databases.
重启数据库再次测试,问题解决
查看到mysql.user表中的权限信息如下:
在未升级之前,使用mysqldump命令会出现
mysqldump: Couldn't execute 'SHOW VARIABLES LIKE 'gtid\_mode'': Table 'performance_schema.session_variables' doesn't exist (1146)
如果在升级后使用mysqldump出现错误:
mysqldump: Couldn't execute 'SHOW VARIABLES LIKE 'gtid\_mode'': Native table 'performance_schema'.'session_variables' has the wrong structure (1682)
只要重新启动mysql服务即可