为了防止用户访问特定的架构,您需要使用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)
在这里,我们将阻止主机名为“ localhost”的用户“ Chris”访问名称为“ sample”的特定架构-
mysql> DELETE FROM mysql.db WHERE Db IN("sample","sample\_%") AND User="Chris" AND Host="localhost";
执行完上面的查询后,您需要使用FLUSH。
mysql> FLUSH PRIVILEGES;