Chronic pain occurs in ~85–90% of chronic pancreatitis (CP) patients. However, as the pathogenesis of CP pain remains to be fully understood, the current therapies for CP pain remain inadequate. Emerging evidence has suggested that the epigenetic modulations of genes are involved in chronic pain. In the present study, intrapancreatic trinitrobenzene sulfonic acid infusions were used to establish a CP model in rats. Mechanical allodynia was measured with von Frey filaments. Immunofluorescent staining analysis was used to observe the expression changes of histone deacetylase 2 (HDAC2) and µ-opioid receptor (MOR), and intrathecal administration of the selective HDAC2 inhibitor AR-42 was used to assess the underlying mechanisms. The expression levels of c-Jun N-terminal kinase (JNK) in the thoracic spinal cord were detected by western blotting, and the mRNA expression levels of interleukin (IL)1-β, IL-6 and tumor necrosis factor (TNF)-α were detected by reverse transcription-quantitative polymerase chain reaction. The results demonstrated that HDAC2 expression was upregulated during the course of CP induction, while MOR activity in the thoracic spinal dorsal horn was significantly suppressed. Intrathecal infusion of AR-42 significantly attenuated CP-induced mechanical allodynia, with rescued MOR activity. Additionally, HDAC2 facilitated the release of inflammatory cytokines, including IL-1β, IL-6 and TNF-α. These results suggested that the underlying mechanisms of HDAC2 regulating MOR activity under CP induction may occur via promoting the release of inflammatory cytokines, thus activating the JNK signaling pathway. The present study suggested that the epigenetic-regulated disturbance of MOR is dependent on the endogenous analgesia system in CP, which may a provide novel therapeutic strategy for treating pain in CP.