Dimerized and trimerized phases for spin-2 bosons in a one-dimensional optical lattice