Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pexpect
- #mysqlVersion()
- #lauch mysql --version command from terminal
- #get substring distriburion number
- #return the distribution number
- def mysqlVersion():
- start = 'Distrib '
- end = ','
- s = pexpect.spawn('mysql --version')
- index = s.expect (['Ver'])
- if index == 0:
- s = s.readline()
- version = s.split(start)[1].split(end)[0]
- else:
- return 'error'
- return version
- # --> End function mysqlVersion
- #checkSqlRootPass()
- def checkSqlRootPass(sqlVersion):
- p = pexpect.spawn('mysql -u root -p')
- p.sendline('\n')
- i = p.expect(['mysql>','ERROR'])
- if i == 0:
- p.sendline('exit;')
- newRootPass = raw_input('No Root Password!!!\nEnter a new root password for MySql:')
- p = pexpect.spawn('mysql -u root -p')
- p.sendline('\n')
- p.sendline('use mysql;')
- #p.interact()
- if(mysqlVersion >= '5.7.6')
- assignMySqlRoot = 'update user set authentication_string=password(\'' + newRootPass + '\') where user=\'root\';'
- p.sendline(assignMySqlRoot)
- p.sendline('flush privileges;')
- p.sendline('quit')
- if i == 1:
- print "incorrect password"
- return
- # --> End function checkSqlRootPass
- sqlVersion = mysqlVersion()
- if(sqlVersion == 'error'):
- else:
- checkSqlRootPass(sqlVersion)
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement