Most groundwater geochemical studies associated with earthquakes have focused on changes in major ions and radon concentration. However, trace elements have also shown a dramatic response to earthquakes and attracted increasing attention. In this study, hydrochemical and water level changes were detected by an artesian well (DZ well) in Yunnan, China, during the 2018 Ms 5.9 Mojiang earthquake. The results show that the major and trace element concentrations changed considerably before and after the earthquake, which were attributed to the mixing of water from different aquifers due to the earthquake-induced alteration of permeability through wavelet analysis of continuous monitoring data and coseismic static strain. In addition, Self-Organizing Map (SOM) and K-means clustering algorithms were used to classify all water samples with 10 trace elements as variables, and the results showed that samples collected in pre- and post-earthquake can be categorized as two groups, showing a significant difference. We argue that the response of trace elements remains unaffected by their initial concentration levels. Notably, both high- and low-concentration trace elements (e.g., Cs, Rb, V, etc.) exhibit discernible changes in response to the Ms 5.9 Mojiang earthquake. These observations corroborate the efficacy of clustering methodologies in delineating seismic-induced concentration shifts and furnish fresh insights into the anomalous behavior of trace elements during the earthquake.