  In this paper, we construct a new family of distance-optimal binary cyclic
codes with the minimum distance $6$ and a new family of distance-optimal
quaternary cyclic codes with the minimum distance $4$. We also construct
several families of cyclic and negacyclic codes over ${\bf F}_2$, ${\bf F}_3$,
${\bf F}_4$, ${\bf F}_5$, ${\bf F}_7$ and ${\bf F}_9$ with good parameters
$n,\,k,\,d$, such that the maximal possible minimum distance $d_{max}$ of a
linear $[n, k]_q$ code is at most $d_{max} \leq d+8$. The first codes in these
families have optimal or best known minimum distances. $145$ optimal or best
known codes are constructed as cyclic codes, negacyclic codes, their shortening
codes and punctured codes. All optimal or best known codes constructed in this
paper are not equivalent to the presently best known codes. Several infinite
families of negacyclic $[n,\frac{n+1}{2}, d]_q$ codes or $[n, \frac{n}{2},
d]_q$ codes, such that their minimum distances satisfy $d\approx
O(\frac{n}{\log_q n})$, are also constructed. These are first several families
of such negacyclic codes.
