我正在尝试在PHP(特别是Laravel)中创建一个MySQL视图,我遇到了一个奇怪的错误:
[PDOException]
SQLSTATE[42000]: SSyntax error or access violation: 1142 ANY command denied to user 'user'@'localhost' for table '/tmp/#sql_475_0'
Run Code Online (Sandbox Code Playgroud)
在MySQL中直接运行create语句可以正常工作.如果我删除了视图的连接,那么一切正常.用户具有完全权限(GRANT ALL).广泛的谷歌搜索没有返回任何类似的东西.
我的代码如下,稍微简化,运行第4个语句创建jobs_view时产生错误.
DB::statement("
CREATE VIEW quote_response_count AS (
SELECT job_id, COUNT(quotes.id) as total FROM quotes
INNER JOIN quote_requests on quote_requests.quote_id = quotes.id
INNER JOIN quote_responses on quote_responses.quote_request_id = quote_requests.id
GROUP BY job_id
);
");
DB::statement("
CREATE VIEW customer_paid AS (
SELECT job_id, SUM(amount) as total FROM transactions
WHERE category = 'customer payment' AND is_verified = 1
GROUP BY job_id, category
); …Run Code Online (Sandbox Code Playgroud)