MSE is an important parameter in drilling process as it determines drilling efficiency. Therefore, accurately predicting the MSE during drilling and real-time adjusting the drilling parameters to enhance drilling efficiency have been persistent research topics. In this paper, based on Log Data, including WOB, ROP, RPMX and other parameters, and compares the ability of six machine learning methods to predict MSE. The findings indicate that the CNN-LSTM-Attention model combines the spatial feature extraction capability of CNN and the temporal sequence dependency learning ability of LSTM, while utilizing attention mechanisms to focus on important information. It predicts MSE more accurately than other models, exhibiting a better fit between predicted values and actual values compared to the traditional LSTM model, with a correlation coefficient (R2) of 0.93. This demonstrates the effectiveness of combining temporal and spatial features in predicting drilling parameters. Using the trained model, real-time optimization of drilling parameters is performed to search for the optimal MSE within a certain range, while outputting the corresponding RPM and WOB. Ultimately, the average MSE of the target well decreased by 35.6%. The research findings hold significant importance in reducing MSE and improving drilling efficiency.