To achieve rapid and accurate identification of genetically modified (GM) and non-GM rapeseed oils, a support vector machine (SVM) model based on an improved mayfly optimization algorithm, coupled with the terahertz time-domain spectroscopy, is proposed. Two types of GM rapeseed oils and two types of non-GM rapeseed oils were selected as research subjects. Their spectral information was acquired using the terahertz time-domain spectroscopy. Observations show that GM rapeseed oils exhibit stronger terahertz absorption characteristics than non-GM rapeseed oils. However, their absorption spectra are highly similar, making direct differentiation challenging through visual inspection alone. Therefore, SVM was used for spectral recognition. Considering that the classification performance of SVM was significantly affected by its parameters, the mayfly optimization algorithm was combined to optimize these parameters. Furthermore, adaptive inertia weight and Lévy flight strategies were introduced to enhance the global search capability and robustness of the mayfly optimization algorithm, addressing the issue of easily becoming trapped in local optima during the optimization process. Moreover, principal component analysis was applied to reduce the dimensionality of the absorbance data in the 0.3-1.8 THz range, aiming to extract critical features, thus enhancing modeling efficiency and reducing redundancy in spectral data. Experimental results demonstrate that the improved mayfly optimization algorithm effectively identifies the optimal parameter combination for SVM, thereby enhancing the overall performance of the identification model. The proposed SVM model, utilizing the improved mayfly optimization algorithm, achieves a recognition accuracy of 100% for the four types of rapeseed oils, surpassing the 98.15% accuracy achieved by the SVM model with the original mayfly optimization algorithm. Thus, this study presents a rapid and effective new approach for discriminating GM rapeseed oils and offers a valuable reference for identifying other genetically modified substances.