简体   繁体   English

MySQL:如何检查用户(自身)是否具有创建临时表的权限

[英]MySQL: How To Check If User (Self) Has Permission To Create Temporary Tables

我必须使用哪种查询来检查查询用户是否具有在数据库中创建临时表的权限?

I do not know if there is an elegant way of doing this with a query, but a "hackish" type of way to do it would be to use a mysql_query() and see if you get a result for that table or an error. 我不知道是否有一种优雅的查询方法,但是使用“ hackish”类型的方法是使用mysql_query()并查看是否得到该表的结果或错误。

function checkCreateTempPermission($table) {
     $res = mysql_query("CREATE `$table` "); // modify this to be your temporary table code.
     if ($res === false) {
         if (strstr(mysql_error(), "command denied to user")) {
              return false;
         }else {
              // some other error happened not sure how you want to handle it so left blank.
         }
     }else {
         return true;
     }
}

I have not tested this at all , more or less a theory of how it could be done. 我根本没有测试过它,或多或少没有关于如何完成它的理论 Alternatively, you can write a script that runs this SQL: 或者,您可以编写运行此SQL的脚本:

Show grants for myuser;

And then loop through that testing if they have access for that table. 然后,如果他们有权访问该表,则循环进行该测试。 This would take a bit more work, but at least would not error out. 这将需要更多的工作,但至少不会出错。 Hope that helps to get you started. 希望能帮助您入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM