Here's how we know:
* Mg represents the element magnesium.
* I represents the element iodine.
* The subscript 2 indicates that there are two iodine atoms for every one magnesium atom.
Therefore, the name of the compound is magnesium iodide.