The production of D* and D mesons in inelastic scattering of 160 GeV/c muons off a ^6LiD target has been investigated with the COMPASS spectrometer at CERN for 0.003 (GeV/c)^2 < Q^2 < 10 (GeV/c)^2 and 3x10^-5< x_Bj < 0.1. The study is based on 8100 events where a D^0 or anti D^0 is detected subsequently to a D*+ or D*- decay, and on 34000 events, where only a D^0 or anti D^0 is detected. Kinematic distributions of D*, D and K*_2 are given as a function of their energy E, transverse momentum p_T, energy fraction z, and of the virtual photon variables nu, Q^2 and x_Bj. Semi-inclusive differential D* production cross-sections are compared with theoretical predictions for D* production via photon-gluon fusion into open charm. The total observed production cross-section for D*+/- mesons with laboratory energies between 22 and 86 GeV is 1.9 nb. Significant cross-section asymmetries are observed between D*+ and D*- production for nu<40 GeV and z>0.6.