Rimuovere Utenti Dal SQL Server
il comando DROP USER rimuove un utente dal SQL Server ma e' bene precisare che da solo esso non e' sufficiente, la rimozione dell'utente (generalmente) non si concretizza con la contemporanea rimozione dei permessi ad esso correlati.
Si procede per tanto come segue:
Rimozione dei privilegi;
MariaDB [(none)]> SHOW GRANTS FOR 'iu6crh'@'%';
+-------------------------------------------------------------------------------------------------------+
| Grants for iu6crh@% |
+-------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'iu6crh'@'%' IDENTIFIED BY PASSWORD '*6DA413D8ACD33A112877D31A8BD9DDFB36411631' |
| GRANT ALL PRIVILEGES ON `hamlog`.* TO 'iu6crh'@'%' |
+-------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
MariaDB [(none)]> REVOKE ALL privileges ON hamlog.* FROM 'iu6crh'@'%';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SHOW GRANTS FOR 'iu6crh'@'%';
+-------------------------------------------------------------------------------------------------------+
| Grants for iu6crh@% |
+-------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'iu6crh'@'%' IDENTIFIED BY PASSWORD '*6DA413D8ACD33A112877D31A8BD9DDFB36411631' |
+-------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
Rimozione dell'utente;
MariaDB [(none)]> SELECT User, Host, Password, password_expired FROM mysql.user;
+--------+-----------+-------------------------------------------+------------------+
| User | Host | Password | password_expired |
+--------+-----------+-------------------------------------------+------------------+
| root | localhost | | N |
| iu6crh | % | *6DA413D8ACD33A112877D31A8BD9DDFB36411631 | N |
+--------+-----------+-------------------------------------------+------------------+
2 rows in set (0.00 sec)
MariaDB [(none)]> DROP USER iu6crh;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SELECT User, Host, Password, password_expired FROM mysql.user;
+------+-----------+----------+------------------+
| User | Host | Password | password_expired |
+------+-----------+----------+------------------+
| root | localhost | | N |
+------+-----------+----------+------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
Sarebbe opportuno aggiungere che, come riportato dal Manuale, se sul sistema è in uso MariaDB, l'esecuzione della query DROP USER comporta anche la rimozione di tutte le righe delle tabelle grant che impostano privilegi per l'utente oggetto della nostra azione, rendendo di fatto non più necessaria la rimozione preventiva dei privilegi. Tuttavia questa procedura resta una pratica di buona gestione del sistema.