Based on HSAB rules, a series of oxygen-containing ionic liquids were synthesized as lubricants for magnesium alloy, and they exhibited much better lubricating performance than the conventional ionic liquid LF104. Among them, the carboxylic ionic liquid (N4444-OA) that with better adsorption property but lower reactivity exhibited the best lubrication performance. Characterizations of the worn surface revealed that the better lubrication performance of N4444-OA can be attributed to the formation of an inorganic-organic double layer tribofilm consisting of a metal oxide layer and an organic layer. This study gives an idea to design high-performance magnesium alloy lubricants, that the good lubricant should have better adsorption performance but lower chemical activities.