从 MySQL 5.1 更新到 5.5 - 一切都很好。我意识到了这些差异,并且网站接受了升级,只有一个除外。
但是查询太复杂了,我看不出哪里出了问题......
下面是5.1中的工作
SELECT DISTINCT SQL_CACHE *
FROM Regions
WHERE (region_id IN
(SELECT SQL_CACHE included_region_id AS region_id
FROM Contains_areas
WHERE region_id =
(SELECT toplevel_region_id AS region_id
FROM Sites
WHERE site_url = 'http://www.domainname.com/' LIMIT 1))
OR (region_id =
(SELECT toplevel_region_id AS region_id
FROM Sites
WHERE site_url = 'http://www.domainname.com/' LIMIT 1))
AND user_id='1')
ORDER BY region ASC
但是在5.5中,错误是
“您的 SQL 语法有错误;请检查与您的 MySQL 服务器版本相对应的手册,了解在第 26 行的 'AS Region_id FROM Contains_areas WHERE Region_id IN ( SELE' 附近使用的正确语法”
如果在我搜索答案时能够识别出错误,我将不胜感激,但这个查询超出了我的能力范围。
提前致谢
最佳答案
MySQL 5.5.3 中不再允许在子查询中使用
SQL_CACHE
和 SQL_NO_CACHE
:
The SQL_CACHE and SQL_NO_CACHE options affect caching of query results in the query cache (see Section 8.9.3, “The MySQL Query Cache”). SQL_CACHE tells MySQL to store the result in the query cache if it is cacheable and the value of the query_cache_type system variable is 2 or DEMAND. With SQL_NO_CACHE, the server does not use the query cache. It neither checks the query cache to see whether the result is already cached, nor does it cache the query result. (Due to a limitation in the parser, a space character must precede and follow the SQL_NO_CACHE keyword; a nonspace such as a newline causes the server to check the query cache to see whether the result is already cached.)
For views, SQL_NO_CACHE applies if it appears in any SELECT in the query. For a cacheable query, SQL_CACHE applies if it appears in the first SELECT of a view referred to by the query.
As of MySQL 5.5.3, these two options are mutually exclusive and an error occurs if they are both specified. Also, these options are not permitted in subqueries (including subqueries in the FROM clause), and SELECT statements in unions other than the first SELECT.
关于升级后MySQL语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24320137/