Files
CyberPanel/install/mysqlUtilities.py

47 lines
1.3 KiB
Python
Raw Normal View History

2017-10-24 19:16:36 +05:00
import pexpect
import installLog as logging
import subprocess, shlex
2017-10-24 19:16:36 +05:00
class mysqlUtilities:
@staticmethod
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]
createDB = "CREATE DATABASE " + dbname
2017-10-24 19:16:36 +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
if res == 1:
return 0
2017-10-24 19:16:36 +05:00
createUser = "CREATE USER '" + dbuser + "'@'localhost' IDENTIFIED BY '" + dbpassword + "'"
2017-10-24 19:16:36 +05:00
command = 'mysql -u root -p' + password + ' -e "' + createUser + '"'
2017-10-24 19:16:36 +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
if res == 1:
return 0
2017-10-24 19:16:36 +05:00
else:
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
if res == 1:
return 0
2017-10-24 19:16:36 +05:00
return 1
except BaseException, msg:
return 0