瞎折腾,把mysql的root权限弄没了。。。
现象如下:
mysql> select host,user,password from mysql.user; ERROR 1142 (42000): SELECT command denied to user 'root'@'localhost' for table 'user' mysql> grant all privileges on *.* to 'root'@'%' identified by "root" with grant option; ERROR 1045 (28000): Access denied for user 'root'@'' (using password: YES) mysql> show grants for root; ERROR 1141 (42000): There is no such grant defined for user 'root' on host '%' mysql> select * from mysql.user\G ERROR 1142 (42000): SELECT command denied to user 'root'@'localhost' for table 'user' mysql> SELECT USER(); +----------------+ | USER() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.02 sec) mysql> ^CCtrl-C -- exit!
解决:创建带有root权限的用户,先跳过授权表dengl
root@clone1:/usr/local/mysql/bin 01:00:54> sudo kill -9 `ps -ef|grep mysql|grep -v grep|awk '{print $2}'` [1]+ 已杀死 /usr/local/mysql/bin/mysqld_safe --skip-grant-tables root@clone1:/usr/local/mysql/bin 01:01:38> root@clone1:/usr/local/mysql/bin 01:01:38> root@clone1:/usr/local/mysql/bin 01:01:38> root@clone1:/usr/local/mysql/bin 01:01:39> /usr/local/mysql/bin/mysqld_safe --skip-grant-tables& [1] 26789 root@clone1:/usr/local/mysql/bin 01:01:41>
mysql> select * from mysql.user\G *************************** 1. row *************************** Host: User: root Password: *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B Select_priv: N Insert_priv: N Update_priv: N Delete_priv: N Create_priv: N Drop_priv: N Reload_priv: N Shutdown_priv: N Process_priv: N File_priv: N Grant_priv: N References_priv: N Index_priv: N Alter_priv: N Show_db_priv: N Super_priv: N Create_tmp_table_priv: N Lock_tables_priv: N Execute_priv: N Repl_slave_priv: N Repl_client_priv: N Create_view_priv: N Show_view_priv: N Create_routine_priv: N Alter_routine_priv: N Create_user_priv: N Event_priv: N Trigger_priv: N Create_tablespace_priv: N ssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 plugin: authentication_string: NULL 1 row in set (0.01 sec)
看见没?权限全是N。。。我们先把这条记录干掉,然后插入一条:
mysql> delete from mysql.user where user='root'; Query OK, 1 row affected (0.00 sec) mysql> use mysql Database changed mysql> insert into user (Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv, Create_view_priv, Show_view_priv, Create_routine_priv, Alter_routine_priv, Create_user_priv, Event_priv, Trigger_priv,Create_tablespace_priv,User,Password) values ( 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','root','root'); Query OK, 1 row affected, 3 warnings (0.01 sec) mysql> mysql> UPDATE user SET Password=PASSWORD('root') where USER='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> select * from mysql.user\G *************************** 1. row *************************** Host: User: root Password: *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Reload_priv: Y Shutdown_priv: Y Process_priv: Y File_priv: Y Grant_priv: Y References_priv: Y Index_priv: Y Alter_priv: Y Show_db_priv: Y Super_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Execute_priv: Y Repl_slave_priv: Y Repl_client_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: Y Create_user_priv: Y Event_priv: Y Trigger_priv: Y Create_tablespace_priv: Y ssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 plugin: authentication_string: NULL 1 row in set (0.00 sec) mysql> ^CCtrl-C -- exit!