To sort by a specific element use a pure function with the number in question. For your case (the second element) just do:
SortBy[a, #[[2]] &]
{{7, 1, 4}, {1, 2, 3}, {12, 4, 8}, {3, 5, 6}, {10, 7, 1}}
You can also use Sort
like this:
Sort[a, #1[[2]] < #2[[2]] &]