In this paper, TiN coatings with grain sizes of 54.8 nm, 68.8 nm, 91.5 nm and 136.9 nm was prepared on the aluminum alloy by extending the coating deposition duration. The mechanical performance under nanoindentation and sand erosion were evaluated. The results show that there is a positive correlation between the hardness of the TiN coating and the grain size. Under the shear stress, the primary mechanism governing the mechanical behavior of the TiN coating is grain boundary sliding when the grain size is less than 70 nm. However, when the grain size surpasses 90 nm, the mechanical response shifts towards the emergence of shear bands and lateral cracks. During nanoindentation loading, TiN coatings with different grain size shows amorphous transformation. Sand erosion experiments demonstrate that refining the grain structure enhances the coordination capability of the TiN coating during plastic deformation, leading to a substantial increase in the amount of sand needed to initiate coating cracks. Simultaneously, the augmentation in the quantity of grain boundaries enhances the TiN coating's capacity for coordinating during plastic deformation, ultimately bolstering its resistance to crack propagation and erosion.