Mayfly algorithm is a new intelligent optimization algorithm with unique optimization capabilities recently proposed. It has strong research value, but there are also insufficient explorations, and it is easy to fall into the problem of local optimization. This paper aims to improve the optimization performance of the mayfly algorithm and explore its application value in practical engineering optimization problems. An improved mayfly algorithm based on the median position of the group is proposed. In its velocity update, the median position of the group is introduced with emphasis, and a non-linear gravity coefficient is introduced at the same time. Through the benchmark test function, its superiority in exploitation, convergence speed and accuracy and the improvement of exploration are verified. At the same time, the simulation model of the hydro-turbine governor using MATLAB/Simulink is established, and 10% frequency disturbance experiments of this model are carried out separately in two typical working conditions. The experiments results show that the optimal ITAE index value of the system obtained by the improved mayfly algorithm is smaller, and 16.5 and 18.1 iterations to complete on average. In addition, the experiments results reveal that the PID parameters optimized by the improved mayfly algorithm can make the dynamic performance of the regulation system better than other popular swarm intelligence algorithms, where the overshoot decreased by more than 3.1%, and the adjustment time also decreased in different degrees. The proposal of the median position of the group provides a new idea for the improvement of the swarm intelligence optimization algorithm. Meanwhile, a new effective method for optimizing the PID parameters of the hydro-turbine governor has been found.