一直以來用root@localhost 開帳號都沒什麼問題,開了一個[email protected] 給dev 用,就出問題了
1 2 |
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' |
檢查一下權限,發現也沒問題
1 2 3 4 5 6 |
mysql > show grants; +—————————————————+ | Grants for root@127.0.0.1 | +—————————————————+ | GRANT ALL PRIVILEGES ON *.* TO ‘root’@’127.0.0.1’ | +—————————————————+ |
再往下查
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
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 裡
解法:
1 2 |
mysql> UPDATE mysql.user SET Grant_priv = ‘Y’ WHERE user = ‘root’ AND host = ‘127.0.0.1’; mysql> flush privileges; |
打完收工!
(Visited 590 times, 1 visits today)