The real part of optical conductivity, $text{Re}sigma(omega)$, of the Mott insulators has a large amount of information on how spin and charge degrees of freedom interact with each other. By using the time-dependent density-matrix renormalization group, we study $text{Re}sigma(omega)$ of the two-dimensional Hubbard model on a square lattice at half filling. We find an excitonic peak at the Mott-gap edge of $text{Re}sigma(omega)$ not only for the two-dimensional square lattice but also for two- and four-leg ladders. For the square lattice, however, we do not clearly find a gap between an excitonic peak and continuum band, which indicates that a bound state is not well-defined. The emergence of an excitonic peak in $text{Re}sigma(omega)$ implies the formation of a spin polaron. Examining the dependence of $text{Re}sigma(omega)$ on the on-site Coulomb interaction and next-nearest neighbor hoppings, we confirm that an excitonic peak is generated from a magnetic effect. Electron scattering due to an electron-phonon interaction is expected to easily suppress an excitonic peak since spectral width of an excitonic peak is very narrow. Introducing a large broadening in $text{Re}sigma(omega)$ by modeling the electron-phonon coupling present in La$_{2}$CuO$_{4}$ and Nd$_{2}$CuO$_{4}$, we obtain $text{Re}sigma(omega)$ comparable with experiments.