Cyclic codes are a subclass of linear codes and have applications in consumer electronics, data storage systems, and communication systems as they have efficient encoding and decoding algorithms. Let \(\mathcal{C}_{(u, v)}\) denote the ternary cyclic code with two nonzeros \(\alpha^u\) and \(\alpha^v\) , where \(\alpha\) is a generator of \(\mathbb{F}_{3^m}^*\) and \(0\leq u,v\leq 3^m-2\) . In this paper, by analyzing the solutions of certain equations over \(\mathbb{F}_{3^m}\) , we present two classes of optimal ternary cyclic codes \(\mathcal{C}_{(1, e)}\) in the case of \(m\) is odd and two classes of optimal ternary cyclic codes \(\mathcal{C}_{(u, v)}\) , respectively. Moreover, using the multivariate method, five classes of optimal ternary cyclic codes \(\mathcal{C}_{(1, e)}\) with explicit values $e$ are given. It can be verified by analyzing cyclotomic cosets that these codes are not equivalent to any known codes.