We study the effect of magnetic field on heavy quark-antiquark pair in both Einstein-Maxwell (EM) and Einstein-Maxwell-dilaton (EMD) model. The interquark distance, free energy, entropy, binding energy, and internal energy of the heavy quarkonium are calculated. It is found that the free energy suppresses and the entropy increases quickly with the increase of the magnetic field B . The binding energy vanishes at smaller distance when increasing the magnetic field, which indicates the quark-antiquark pair dissociates at smaller distance. The internal energy which consists of free energy and entropy will increase at large separating distance for a nonvanishing magnetic field. These conclusions are consistent both in the EM and EMD model. Moreover, we also find that the quarkonium will dissociate easier in the parallel direction than that in the transverse direction for EMD model, but the conclusion is opposite in EM model. Lattice results are in favor of EMD model. Besides, a Coulomb-plus-linear potential (Cornell potential) can be realized only in EMD model. Thus, a dilaton field is proved to be important in holographic model. Finally, we also show that the free energy, entropy, and internal energy of a single quark in EMD model with the presence of magnetic field.