A crane system often works in a complex environment. Traditional system identification methods are difficult to accurately model crane system identification's real dynamic performance, whether online or offline. Therefore, a Data-driven model predictive control (D-MPC) algorithm is proposed in this paper. Based on Bayesian optimization, the crane's local linear dynamic model is learned to improve the rapidly anti-swing and precise positioning. By collecting data through closed-loop experiments and using Bayes to construct the Gaussian model for guiding learning, the controller parameters and prediction model with the best closed-loop performance can be found. Simulation results show that we explicitly find the dynamics model that produces the best control performance for the actual system, and the method can quickly suppress the swing and realize the accurate trolley positioning. The results verify the proposed control algorithm's effectiveness, feasibility and superior performance of the proposed method by comparing it with double-closed-loop proportional-integral- derivative (PID).