C#中调用mysql存储过程出现SELECT command denied for table 'proc'

在使用C#调用MySQL存储过程时遇到权限问题,错误提示'SELECT command denied for table 'proc''.问题出现在非root用户尝试调用存储过程。解决方案包括设置UseProcedureBodies为false,要求参数顺序与存储过程定义一致,或者考虑使用ODBC连接。官方Bug报告和全面的.NET连接字符串资源链接提供更多信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


在root账号中,可以正常调用存储过程.

换到其他账号时,同一存储过程名调用出现问题.

error:SELECT command denied to user 'common_user'@'localhost' for table 'proc'

搜索解决方案:

MySqlConnection myconnection = new MySqlConnection("server=localhost;user id=common_user; password=***;database=testdb; UseProcedure Bodies=false;Charset=utf8;");

在网上搜索本句含义:

Name : Use Procedure Bodies  
Default : true  
Description : Setting this option to false indicates that the user connecting to the database does not have the SELECT privileges for the mysql.proc (stored procedures) table. When to set to false, Connector/NET will not rely on this information being available when the procedure is called. Because Connector/NET will be unable to determine this information, you should explicitly set the types of the all the parameters before the call and the parameters should be added to the command in the exact same order as they appear in the procedure definition. This option was added in Connector/NET 5.0.4 and Connector/NET 1.0.10. 

 大体意思是说:

当设置时use procedure bodies=false,存储过程的参数需要与程序里的参数顺序一致.

还未结束.

在mysql官方.给出了这样设置会有一个BUG.

http://bugs.mysql.com/bug.php?id=36694

当然这样更好的解决方法可以使用ODBC连接来实现.

这里不再详细说明.

附上.NET连接mysql的连接字符串网址(比较全面的连接归类):

http://www.connectionstrings.com/mysql

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值