Tag Archives: privilege

MySQL grant and revoke

mysql -uroot -pRooTIsmE -h mysqlServer

create user special@’%’ identified by ‘password’;
grant all on *.* to special@’%’ identified by ‘password’;
revoke drop, delete on *.* from special@’%’ identified by ‘password’;
flush privileges;
show grants for special@’%’;
exit;

mysql -uspecial -ppassword
create database huypv;
drop database huypv;
#ERROR 1044 (42000): Access denied for user ‘special’@’%’ to database ‘huypv’

Nào thì grants privileges mới chả gán quyền

mysql> show grants for ‘vietnam’@’192.168.1.114’;
+——————————————————————-+
| Grants for vietnam@192.168.1.114                                    |
+——————————————————————-+
| GRANT USAGE ON *.* TO ‘vietnam’@’192.168.1.114’                     |
| GRANT ALL PRIVILEGES ON `vietnam_xxx`.* TO ‘vietnam’@’192.168.1.114’ |
+——————————————————————-+
2 rows in set (0.00 sec)

mysql> grant all privileges on vietnam.* to ‘vietnam’@’192.168.1.114’ identified by ‘vietnam_secret_key’;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on vietnam_xxx.* to ‘vietnam’@’192.168.1.114’ identified by ‘vietnam_secret_key’;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)

mysql> show grants for ‘vietnam’@’192.168.1.114’;
+——————————————————————————————————————+
| Grants for vietnam@192.168.1.114                                                                                   |
+——————————————————————————————————————+
| GRANT USAGE ON *.* TO ‘vietnam’@’192.168.1.114’ IDENTIFIED BY PASSWORD ‘*FDA32083C6301D4B9D2D49CFED881767E0XXXXXX’ |
| GRANT ALL PRIVILEGES ON `vietnam`.* TO ‘vietnam’@’192.168.1.114’                                                     |
| GRANT ALL PRIVILEGES ON `vietnam_xxx`.* TO ‘vietnam’@’192.168.1.114’                                                |
+——————————————————————————————————————+
3 rows in set (0.00 sec)

[!] Thay 192.168.1.114 bằng % để đi đâu cũng vẫn mân mê được đê bê (DB)!!!