clg4 clg4 - 1 year ago 51
SQL Question

MySQL 5.6 stop and start (restart) server which has password, in Windows 7, using Python

simply would like to restart a MySQL5.6 server in a python script, on Windows 7. The server has a password

In a cmd prompt, I can stop the server using:

"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqladmin" -u root -p shutdown

But this prompts for a password (which is needed). Entering the password in the command, still prompts for password.

So first, how can I shutdown and restart in cmd prompt, then is it possible to do in python?


The answer is as follows:

Run cmd.exe as Administrator by 1) right clicking on cmd.exe and selecting 'Run as Administrator', or 2) if you want to run the batch file from Task Scheduler, you will need to create a shortcut to the batch file, and then right click on the shortcut, select properties, select shortcut, and check off the run as administrator box. Then run the shortcut in Task scheduler.

In your batch file, which will now run as administrator, you use:

net stop MySQL56

net start MySQL56

where MySQL56 is the name of your MySQL service.

Of course you can easily run the batch file or shortcut from within python also.

Works on my Windows 7 x64...