Bayesian network structure learning is one of the current research hotspots in fields such as statistics and machine learning. Although it has great potential and application prospects, when there are too many variables, this type of algorithm will not be able to accurately and efficiently provide the optimal solution. In response to this issue, this study improved the dragonfly swarm optimization algorithm and solved the problem of variable type conflicts through binary discretization, applying it to the Bayesian network structure learning algorithm. According to the algorithm testing results, when the sample size is 1000 and the missing rate is 30%, the Bayesian Information Criterion (BIC) of the proposed algorithm is -7896. Under the same missing rate, when the sample size is 2000, the proposed algorithm BIC is -15114. Their BIC scores are superior to the greedy search algorithm and the sine cosine algorithm used for comparison. The proposed algorithm provides a promising development direction for the field of Bayesian network structure learning.