A thorough structural exploration was performed for MgB6 combining the global structure searching method with first-principles calculations. Besides the known Cmcm phase, new phases, i.e. I4/mmm, C2/m-I, C2/m-II and P21/m, were predicted to be stable in the pressure range of 18-100 GPa. Unexpectedly, Cmcm-MgB6 was found to be a semiconductor with an indirect band gap of 0.38 eV with the HSE06 functional, in good agreement with the experimental finding. I4/mmm-MgB6 stabilized above 18 GPa exhibits semimetallic behaviour with a topological node-line near the Fermi level. Consequently, C2/m-I MgB6 with a sandwich structure similar to MgB2 is predicted to be a superconductor with a critical temperature (Tc) of 9.5 K. By analysing the electronic structure, the intriguing semiconductor-semimetal-superconductor transition may be ascribed to the delocalization of more B-p electrons in the boron sublattice. The novel functions uncovered for MgB6 may inspire more efforts to discover materials with intriguing properties.