Mysql: ALL PRIVILEGES 帳號依然無開帳號 ( ERROR 1044)

分類:T-SQL


一直以來用root@localhost 開帳號都沒什麼問題,開了一個root@127.0.0.1 給dev 用,就出問題了

mysql> GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON `t_table`.* TO 't_user'@'%' IDENTIFIED BY "xxxx";
ERROR 1044 (42000): Access denied for user 'root'@'127.0.0.1' to database 't_table'

檢查一下權限,發現也沒問題

mysql > show grants;
+—————————————————+
| Grants for root@127.0.0.1 |
+—————————————————+
| GRANT ALL PRIVILEGES ON *.* TO ‘root’@’127.0.0.1’ |
+—————————————————+

再往下查

mysql> select * from mysql.user where user='root' \G
*************************** 1. row ***************************
                  Host: localhost
                  User: root
           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: mysql_native_password
 authentication_string: *xx
      password_expired: N
 password_last_changed: 2019-08-28 02:24:39
     password_lifetime: NULL
        account_locked: N
*************************** 2. row ***************************
                  Host: 127.0.0.1
                  User: root
           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: N
       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: mysql_native_password
 authentication_string: *xx
      password_expired: N
 password_last_changed: 2019-08-28 03:50:21
     password_lifetime: NULL
        account_locked: N
2 rows in set (0.00 sec)

眼尖的你有發現嗎 ? “Grant_priv: N”

查了一下google 大神,原來必需要有 Grant_priv 才能 Grant, 卻不包含在 ALL PRIVILEGES 裡

解法:

mysql> UPDATE mysql.user SET Grant_priv = ‘Y’ WHERE user = ‘root’ AND host = ‘127.0.0.1’;
mysql> flush privileges;

打完收工!


Tags:mysql