Galactinol, a galactosyl donor, is the key substrate in raffinose family oligosaccharide (RFO) biosynthesis pathways. Many studies proved that galactinol also regulates some defense-related genes to be transcribed as a sugar signal under biotic and abiotic stresses. There are four galactinol synthase (SlGolS) genes in tomato. In this study, SlGolS1, SlGolS2, and SlGolS4 responded to cold stress, especially SlGolS1 stems treated for 12 h and SlGolS4 stems treated for 24 h. Under heat stress, the expression levels of SlGolS1, SlGolS2, and SlGolS3, especially SlGolS1 and SlGolS2, increased in leaves, roots, and stems. When expressed in E. coli cells, SlGolS2 and SlGolS4 enhanced cold tolerance, whereas SlGolS1 and SlGolS3 improved heat tolerance. These results suggested that SlGolS family members played different roles in tolerance to cold and heat stresses. In addition, the application of galactinol or galactinol + α-galactosidase inhibitor (DGJ) improved the cold and heat tolerances of tomato plants, whereas the single application of DGJ had no effect. Interestingly, the applications of DGJ, galactinol, and galactinol + DGJ also affected the expression levels of SlRS, SlSTS, and SlAGAL under cold and heat stresses. These findings indicated that galactinol was involved in the biosynthesis pathways of RFOs as a galactosyl donor and regulated the expression levels of RFO biosynthesis and breakdown-related genes as a sugar signal under cold and heat stresses.