Advertisement
Guest User

Untitled

a guest
Nov 30th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import pexpect
  2.  
  3. #mysqlVersion()
  4. #lauch mysql --version command from terminal
  5. #get substring distriburion number
  6. #return the distribution number
  7. def mysqlVersion():
  8. start = 'Distrib '
  9. end = ','
  10. s = pexpect.spawn('mysql --version')
  11. index = s.expect (['Ver'])
  12. if index == 0:
  13. s = s.readline()
  14. version = s.split(start)[1].split(end)[0]
  15. else:
  16. return 'error'
  17. return version
  18. # --> End function mysqlVersion
  19.  
  20. #checkSqlRootPass()
  21.  
  22. def checkSqlRootPass(sqlVersion):
  23. p = pexpect.spawn('mysql -u root -p')
  24. p.sendline('\n')
  25. i = p.expect(['mysql>','ERROR'])
  26. if i == 0:
  27. p.sendline('exit;')
  28. newRootPass = raw_input('No Root Password!!!\nEnter a new root password for MySql:')
  29. p = pexpect.spawn('mysql -u root -p')
  30. p.sendline('\n')
  31. p.sendline('use mysql;')
  32. #p.interact()
  33. if(mysqlVersion >= '5.7.6')
  34. assignMySqlRoot = 'update user set authentication_string=password(\'' + newRootPass + '\') where user=\'root\';'
  35. p.sendline(assignMySqlRoot)
  36. p.sendline('flush privileges;')
  37. p.sendline('quit')
  38. if i == 1:
  39. print "incorrect password"
  40. return
  41. # --> End function checkSqlRootPass
  42.  
  43. sqlVersion = mysqlVersion()
  44. if(sqlVersion == 'error'):
  45. else:
  46. checkSqlRootPass(sqlVersion)
  47. exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement