2017-10-24 19:16:36 +05:00
|
|
|
import pexpect
|
|
|
|
|
import installLog as logging
|
2018-12-06 15:03:43 +05:00
|
|
|
import subprocess, shlex
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
class mysqlUtilities:
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
2018-12-06 15:03:43 +05:00
|
|
|
def createDatabase(dbname, dbuser, dbpassword):
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
passFile = "/etc/cyberpanel/mysqlPassword"
|
|
|
|
|
|
|
|
|
|
f = open(passFile)
|
|
|
|
|
data = f.read()
|
|
|
|
|
password = data.split('\n', 1)[0]
|
|
|
|
|
|
2018-12-06 15:03:43 +05:00
|
|
|
createDB = "CREATE DATABASE " + dbname
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-12-06 15:03:43 +05:00
|
|
|
command = 'mysql -u root -p' + password + ' -e "' + createDB + '"'
|
|
|
|
|
cmd = shlex.split(command)
|
2019-03-21 23:26:42 +05:00
|
|
|
res = ProcessUtilities.executioner(cmd)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-12-06 15:03:43 +05:00
|
|
|
if res == 1:
|
|
|
|
|
return 0
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-12-06 15:03:43 +05:00
|
|
|
createUser = "CREATE USER '" + dbuser + "'@'localhost' IDENTIFIED BY '" + dbpassword + "'"
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-12-06 15:03:43 +05:00
|
|
|
command = 'mysql -u root -p' + password + ' -e "' + createUser + '"'
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-12-06 15:03:43 +05:00
|
|
|
cmd = shlex.split(command)
|
2019-03-21 23:26:42 +05:00
|
|
|
res = ProcessUtilities.executioner(cmd)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-12-06 15:03:43 +05:00
|
|
|
if res == 1:
|
|
|
|
|
return 0
|
2017-10-24 19:16:36 +05:00
|
|
|
else:
|
2018-12-06 15:03:43 +05:00
|
|
|
dropDB = "GRANT ALL PRIVILEGES ON " + dbname + ".* TO '" + dbuser + "'@'localhost'"
|
|
|
|
|
command = 'mysql -u root -p' + password + ' -e "' + dropDB + '"'
|
|
|
|
|
cmd = shlex.split(command)
|
2019-03-21 23:26:42 +05:00
|
|
|
res = ProcessUtilities.executioner(cmd)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-12-06 15:03:43 +05:00
|
|
|
if res == 1:
|
|
|
|
|
return 0
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
except BaseException, msg:
|
2018-12-06 15:03:43 +05:00
|
|
|
return 0
|