The MSSM is extended to the $U(1)_X$SSM, whose local gauge group is $SU(3)_C times SU(2)_L times U(1)_Y times U(1)_X$. To obtain the $U(1)_X$SSM, we add the new superfields to the MSSM, namely: three Higgs singlets $hat{eta},~hat{bar{eta}},~hat{S}$ and right-handed neutrinos $hat{ u}_i$. It can give light neutrino tiny mass at the tree level through the seesaw mechanism. The study of the contribution of the two-loop diagrams to the MDM of muon under $U(1)_X$SSM provides the possibility for us to search for new physics. In the analytical calculation of the loop diagrams (one-loop and two-loop diagrams), the effective Lagrangian method is used to derive muon MDM. Here, the considered two-loop diagrams include Barr-Zee type diagrams and rainbow type two-loop diagrams, especially Z-Z rainbow two-loop diagram is taken into account. The obtained numerical results can reach $7.4times10^{-10}$, which can remedy the deviation between SM prediction and experimental data to some extent.