Mycat踩坑ERROR 1064 (HY000)

Mycat踩坑ERROR 1064 (HY000)

问题重现

生产环境新搭建的mycat,查询报错:

mysql> select distinct o.* from
    ->         ( select goods_id offer_id, name offer_name, sn offer_code,simple_name,mktPrice,price,state,
    ->         thumbnail,type_id offer_type, marketing_begin_time,marketing_end_time,
    ->         t.tax
    ->         from  prod_goods t
    ->         where 1 = 1
    ->        and t.marketing_begin_time <= sysdate() 
    ->        and  t.marketing_end_time > sysdate())o
    -> ;
ERROR 1064 (HY000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*
LIMIT 100000000' at line 6

而直接连接mysql,不走mycat的话查询是能正常返回结果的。

解决方案

mycat不支持select distinct *,将*替换为具体column名:

mysql> select distinct offer_id,offer_name,offer_code,simple_name,mktPrice,price,state,thumbnail,offer_type,marketing_begin_time,marketing_end_time,tax from
    ->         ( select goods_id offer_id, name offer_name, sn offer_code,simple_name,mktPrice,price,state,
    ->         thumbnail,type_id offer_type, marketing_begin_time,marketing_end_time,
    ->         t.tax
    ->         from  prod_goods t
    ->         where 1 = 1
    ->        and t.marketing_begin_time <= sysdate() 
    ->        and  t.marketing_end_time > sysdate())o
    -> ;
+---------------------+-------------------------------+------------+-------------------------------+----------+-------+-------+-----------+------------+----------------------+---------------------+------+
| offer_id            | offer_name                    | offer_code | simple_name                   | mktPrice | price | state | thumbnail | offer_type | marketing_begin_time | marketing_end_time  | tax  |
+---------------------+-------------------------------+------------+-------------------------------+----------+-------+-------+-----------+------------+----------------------+---------------------+------+
| 1162487289697533953 | a                     | 12344      | a                    |    10000 |     1 | C     | NULL      | 6          | 2019-08-17 06:12:22  | 2019-09-16 06:12:22 | NULL |
| 1162487833723928578 | b                     | NULL       | b                    |        0 |     0 | C     | NULL      | 8          | 2019-08-17 06:14:42  | 2019-09-16 06:14:42 | NULL |
| 1162488027156840449 | c                     | NULL       | c                    |        0 |     0 | C     | NULL      | 6          | 2019-08-17 06:15:28  | 2019-09-16 06:15:28 | NULL |
| 1162488158606327810 | d                     | NULL       | d                    |        0 |     0 | C     | NULL      | 6          | 2019-08-17 06:15:59  | 2019-09-16 06:15:59 | NULL |
| 1162488323824156674 | e                     | NULL       | e                    |        0 |     0 | C     | NULL      | 6          | 2019-08-17 06:16:38  | 2019-09-16 06:16:38 | NULL |
+---------------------+-------------------------------+------------+-------------------------------+----------+-------+-------+-----------+------------+----------------------+---------------------+------+
5 rows in set (0.00 sec)

脚本正常执行

你可能感兴趣的:(mysql)