A driving mechanism used in a railway welding machine that operates along a railway track, comprising: a motor producing a force, and an upper transmission mechanism connected to the motor, characterized in that upper transmission mechanism includes: an upper shaft driven by the motor and including: a shaft key seat, and a shaft key disposed in the shaft key seat, and a coupling mechanism, wherein the upper shaft passes through the coupling mechanism including: a female coupling device, and a male coupling device detachably coupled to the female coupling device through teeth (331, 321), the male coupling device including a shaft keyway configured to receive and be engaged with the shaft key of the upper shaft so that the upper shaft rotates the male coupling device, wherein when the male coupling device is coupled to the female coupling device, the male coupling device transmits the force to the female coupling device, and when the male coupling device is decoupled from the female coupling device, the male coupling device does not transmit the force to the female coupling device. a motor producing a force, and an upper transmission mechanism connected to the motor, characterized in that upper transmission mechanism includes: an upper shaft driven by the motor and including: a shaft key seat, and a shaft key disposed in the shaft key seat, and a coupling mechanism, wherein the upper shaft passes through the coupling mechanism including: a female coupling device, and a male coupling device detachably coupled to the female coupling device through teeth (331, 321), the male coupling device including a shaft keyway configured to receive and be engaged with the shaft key of the upper shaft so that the upper shaft rotates the male coupling device, wherein when the male coupling device is coupled to the female coupling device, the male coupling device transmits the force to the female coupling device, and when the male coupling device is decoupled from the female coupling device, the male coupling device does not transmit the force to the female coupling device. an upper shaft driven by the motor and including: a shaft key seat, and a shaft key disposed in the shaft key seat, and a shaft key seat, and a shaft key disposed in the shaft key seat, and a coupling mechanism, wherein the upper shaft passes through the coupling mechanism including: a female coupling device, and a male coupling device detachably coupled to the female coupling device through teeth (331, 321), the male coupling device including a shaft keyway configured to receive and be engaged with the shaft key of the upper shaft so that the upper shaft rotates the male coupling device, a female coupling device, and a male coupling device detachably coupled to the female coupling device through teeth (331, 321), the male coupling device including a shaft keyway configured to receive and be engaged with the shaft key of the upper shaft so that the upper shaft rotates the male coupling device, wherein when the male coupling device is coupled to the female coupling device, the male coupling device transmits the force to the female coupling device, and when the male coupling device is decoupled from the female coupling device, the male coupling device does not transmit the force to the female coupling device.