The magnetic field created in high energy nuclear collisions will affect the QCD dynamical processes, such as the heavy quark production which happens in the initial stage of the collisions. We calculate in a strong magnetic field the heavy quark production cross section of the process gg→QQ¯\\documentclass[12pt]{minimal} \\usepackage{amsmath} \\usepackage{wasysym} \\usepackage{amsfonts} \\usepackage{amssymb} \\usepackage{amsbsy} \\usepackage{mathrsfs} \\usepackage{upgreek} \\setlength{\\oddsidemargin}{-69pt} \\begin{document}$$ gg\ o Q\\overline{Q} $$\\end{document} at leading order and the corresponding transverse momentum distribution in nucleus-nucleus collisions. In comparison to the QED process, the heavy quark production is dominated by the unique QCD channel with gluon self-interaction. Due to the dimension reduction of quark phase space in a strong magnetic field, the production is concentrated in a very narrow energy region above the threshold. Since the rotational invariance is broken in a magnetic field, the production becomes anisotropic.