SELECT 
  cscart_products_categories.product_id, 
  GROUP_CONCAT(
    IF(
      cscart_products_categories.link_type = "M", 
      CONCAT(
        cscart_products_categories.category_id, 
        "M"
      ), 
      cscart_products_categories.category_id
    )
  ) AS category_ids 
FROM 
  cscart_products_categories 
  INNER JOIN cscart_categories ON cscart_categories.category_id = cscart_products_categories.category_id 
  AND cscart_categories.storefront_id IN (0, 1) 
  AND (
    cscart_categories.usergroup_ids = '' 
    OR FIND_IN_SET(
      0, cscart_categories.usergroup_ids
    ) 
    OR FIND_IN_SET(
      1, cscart_categories.usergroup_ids
    )
  ) 
  AND cscart_categories.status IN ('A', 'H') 
WHERE 
  cscart_products_categories.product_id IN (
    6290, 6085, 6016, 6017, 6084, 6191, 6018, 
    6086, 6081, 6144, 6254, 6228, 6192, 
    6227, 6083, 6230, 6275, 6277, 6291, 
    6258, 6255, 6229, 6256, 6189, 6257, 
    6259, 6145, 6226, 6279, 6278, 6190, 
    6276, 6280, 6260, 6274, 6281, 6282
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00149

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "54.06"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 56,
            "rows_produced_per_join": 56,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (6290,6085,6016,6017,6084,6191,6018,6086,6081,6144,6254,6228,6192,6227,6083,6230,6275,6277,6291,6258,6255,6229,6256,6189,6257,6259,6145,6226,6279,6278,6190,6276,6280,6260,6274,6281,6282))",
            "cost_info": {
              "read_cost": "28.86",
              "eval_cost": "5.60",
              "prefix_cost": "34.46",
              "data_read_per_join": "896"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 2,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "14.00",
              "eval_cost": "0.28",
              "prefix_cost": "54.06",
              "data_read_per_join": "8K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`storefront_id` in (0,1)) and ((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`))) and (`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
6016 522,521,537M
6017 522,521,536M
6018 521,522,536M
6081 521,522,535M
6083 521,522,535M
6084 521,522,537M
6085 521,522,537M
6086 522,521,537M
6144 522,521,535M
6145 522,521,535M
6189 522,521,535M
6190 522,521,535M
6191 522,521,536M
6192 522,521,537M
6226 537M
6227 537M
6228 537M
6229 537M
6230 537M
6254 537M
6255 537M
6256 537M
6257 537M
6258 537M
6259 537M
6260 535M
6274 535M
6275 537M
6276 535M
6277 539M
6278 588M
6279 588M
6280 588M
6281 591M
6282 591M
6290 591M
6291 459M