A motor-driving apparatus, which drives a motor while controlling the motor based on an external command signal from an external device, includes an external command processor, a program storage, a motor controller, a program rewriting unit, a rewriting data input terminal. The external command processor outputs a motor control command from the external command signal based on an external command processing program. The motor controller controls an operation of the motor according to the motor control command based on a motor control program. Further, the external command processing program and the motor control program are previously stored in the program storage. The program rewriting unit rewrites only the external command processing program stored in the program storage based on the program rewriting data received from the rewriting data input terminal.