We perform ab initio simulations of beryllium (Be) and magnesium oxide (MgO) at megabar pressures and compare their structural and thermodynamic properties. We make a detailed comparison of our two recently derived phase diagrams of Be [Wu et al., Phys. Rev. B 104, 014103 (2021)] and MgO [Soubiran and Militzer, Phys. Rev. Lett. 125, 175701 (2020)] using the thermodynamic integration technique, as they exhibit striking similarities regarding their shape. We explore whether the Lindemann criterion can explain the melting temperatures of these materials through the calculation of the Debye temperature at high pressure. From our free energy calculations, we obtained a melting curve for Be that is well represented by the ﬁt Tm(P) = 1564K*[1 + P/(15.8037 GPa)]^0.414 , and a melting line of MgO, which can be well reproduced by the ﬁt Tm(P) = 3010K*(1 + P/a)^(1/c) with a = 10.5797 GPa and c = 2.8683 for the B1 phase and a = 26.1163 GPa and c = 2.2426 for the B2 phase. Both materials exhibit negative Clapeyron slopes on the boundaries between the two solid phases that are strongly aﬀected by anharmonic eﬀects, which also inﬂuences the location of the solid-solid-liquid triple point. We ﬁnd that the quasi-harmonic approximation underestimates the stability range of the low-pressure phases, namely hcp for Be and B1 for MgO. We also compute the phonon dispersion relations at low and high pressure for each of the phases of these materials, and also explore how the phonon density of states is modiﬁed by temperature. Finally, we derive secondary shock Hugoniot curves in addition to the principal Hugoniot curve for both materials, and study their oﬀsets in pressure between solid and liquid branches.