Dye-sensitized solar cells (DSSCs) have received extensive research interest due to their mass production, low cost, environmentally friendly and potential flexibility. TiO2 semiconductor nanomaterials used as photoanodes play a key role in absorbing organic dye molecules. However, organic dyes, such as N3 and N719, can only absorb visible sunlight, which limits the spectral response range of solar cells and reduces the photoelectric conversion efficiency. To solve this problem, rare-earth ions upconversion technology is used to convert near-infrared light into visible light that can be absorbed by organic dyes. In this work, TiO2:Yb3+/Tm3+ nanocrystals doped with Mg2+ ions were synthesized by hydrothermal method, and the optical characteristics and upconversion mechanism of TiO2:Yb3+/Tm3+/Mg2+ were studied. The experimental results show that doping Mg2+ ions remained the crystal structure of anatase TiO2:Yb3+/Tm3+ with the similar morphology of thin sheet. By modifying the local environment around Tm3+ ion, Mg2+ ions enhanced the intensities of blue and red luminescence, leading to an increased absorption and utilization of solar spectral response. Power curve and upconversion mechanism indicated that blue upconversion emission was populated by a two-photon process, while the red upconversion one was populated by one-photon process due to doping Mg2+ ions.