1. 程式人生 > >關於mysql5.7中建立使用者無法登入及grant操作無效問題的處理

關於mysql5.7中建立使用者無法登入及grant操作無效問題的處理

今天用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服務即可