finish initial stage of remote mysql

This commit is contained in:
Usman Nasir
2020-06-26 18:22:20 +05:00
parent f33e33850f
commit c345270585
3 changed files with 162 additions and 102 deletions

View File

@@ -7,15 +7,25 @@ class mysqlUtilities:
try:
passFile = "/etc/cyberpanel/mysqlPassword"
try:
from json import loads
mysqlData = loads(open("/etc/cyberpanel/mysqlPassword", 'r').read())
f = open(passFile)
data = f.read()
password = data.split('\n', 1)[0]
createDB = "CREATE DATABASE " + dbname
initCommand = 'mysql -h %s --port %s -u %s -p%s -e "' % (mysqlData['mysqlhost'], mysqlData['mysqlport'], mysqlData['mysqluser'], mysqlData['mysqlpassword'])
createDB = "CREATE DATABASE " + dbname
except:
passFile = "/etc/cyberpanel/mysqlPassword"
f = open(passFile)
data = f.read()
password = data.split('\n', 1)[0]
createDB = "CREATE DATABASE " + dbname
initCommand = 'mysql -u root -p' + password + ' -e "'
command = initCommand + createDB + '"'
command = 'mysql -u root -p' + password + ' -e "' + createDB + '"'
cmd = shlex.split(command)
res = subprocess.call(cmd)
@@ -24,7 +34,7 @@ class mysqlUtilities:
createUser = "CREATE USER '" + dbuser + "'@'localhost' IDENTIFIED BY '" + dbpassword + "'"
command = 'mysql -u root -p' + password + ' -e "' + createUser + '"'
command = initCommand + createUser + '"'
cmd = shlex.split(command)
res = subprocess.call(cmd)
@@ -33,7 +43,7 @@ class mysqlUtilities:
return 0
else:
dropDB = "GRANT ALL PRIVILEGES ON " + dbname + ".* TO '" + dbuser + "'@'localhost'"
command = 'mysql -u root -p' + password + ' -e "' + dropDB + '"'
command = initCommand + dropDB + '"'
cmd = shlex.split(command)
res = subprocess.call(cmd)