Parts of the area that is now Texas, New Mexico, Arizona, California, Colorado, Utah were first inhabited by the various Native American Tribes who had migrated here thousands of years ago from Asia.
Mexico was where a variety/tribes of indigenous people who descended from ancient civilizations, (I think they were referred to as Mesoamericans) lived.
In 1519 Spain invaded Mexico and by 1521, conquered Mexico.  
Spain then invaded the area that later became U.S. territory.
They "conquered" the indigenous people, created Spanish Land Grants, established the Franciscan Catholic Missions and set up Spanish rule. 
The Puelbo People revolted and kicked them out for about 12 years. 
The Spanish ruled until the Mexican Civil War when Mexico, in 1812, became independent.
A dispute between Texas and Mexico over boundaries caused, in 1847, the Mexican-American War. 
The U.S. won and 1848, ended up with the territories that are now States. 
For short time France ruled Mexico. 
A lot more to it