2

Im trying to start mysql server from python 3.4 script on Max OS X 10.10.4 yet I don't know how to pass the super user password ?

import os 
os.system("sudo /usr/local/mysql/support-files/mysql.server start")


Sudo: no tty present and no askpass program specified

2 Answers 2

3

You are currently going in the right direction. In my system a mysql server is started from /etc/init.d/mysql.

Just use the following code snippet to run your mysql server from a python script.

import os

os.system('sudo /etc/init.d/mysql start')

The best way to run the root commands will be to execute the file itself as root

Simply type sudo python script.py in your shell and you can replace os.system('sudo /etc/init.d/mysql start') with os.system('/etc/init.d/mysql start')

Sign up to request clarification or add additional context in comments.

3 Comments

thanx Arpit, the problem that to use any sudo command u have to pass the super user password !
There is still some error in this. Wait I will fix it... this worked because I already once specified the sudo password in the same terminal. Hence it did not ask for the sudo password again. Let me get back to you with the fix.
I would suggest running the script as root.
1

On Windows OS, first you have to get Administrator authentication and then you can run command line commands using subprocess to start MYSQL80 service.

import pyuac
import sys

def startDB():
    import subprocess as sp
    sp.Popen("net start MYSQL80")
    
if __name__ == "__main__":
    if not pyuac.isUserAdmin():
        try:
            pyuac.runAsAdmin()
        except:
            sys.exit()
    else:        
        startDB()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.