如何防止用户访问 MySQL 中的特定架构?
如要防止用户访问特定架构,需要使用 delete 命令。以下是语法 -
DELETE FROM mysql.db WHERE Db IN("yourSpecificSchema","yourSpecificSchema\_%") AND User = "yourUserName" AND Host = "yourHostName";
让我们实现上述语法,以防止用户访问特定架构。首先,我们从 MySQL.user 表中显示所有用户和主机。
mysql> select user,host from MySQL.user;
这将产生以下输出 -
+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % | | mysql.sys | % | | root | % | | @UserName@ | localhost | | Adam Smith | localhost | | Chris | localhost | | David | localhost | | James | localhost | | John | localhost | | John Doe | localhost | | User1 | localhost | | am | localhost | | hbstudent | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | +------------------+-----------+ 18 rows in set (0.00 sec)
在此,我们将阻止用户“Chris”和主机名“localhost”访问名为“sample”的特定架构 -
mysql> DELETE FROM mysql.db WHERE Db IN("sample","sample\_%") AND User="Chris" AND Host="localhost"; Query OK, 0 rows affected (0.00 sec)
在执行上述查询后,需要使用 FLUSH。
mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.06 sec)
广告