Update index.py

pull/109/head
midoks 3 years ago
parent 1ffb9b3ce6
commit b97a5ace21
  1. 29
      plugins/mysql/index.py

@ -311,25 +311,30 @@ def initMysqlPwd():
def initMysql8Pwd(): def initMysql8Pwd():
time.sleep(6) time.sleep(6)
import MySQLdb as mdb # import MySQLdb as mdb
dbconn = mdb.connect('localhost', 'root', '', '') # dbconn = mdb.connect('localhost', 'root', '', '')
dbconn.autocommit(True) # dbconn.autocommit(True)
dbcurr = dbconn.cursor() # dbcurr = dbconn.cursor()
dbcurr.execute('SET NAMES UTF8MB4') # dbcurr.execute('SET NAMES UTF8MB4')
serverdir = getServerDir() serverdir = getServerDir()
pwd = mw.getRandomString(16) pwd = mw.getRandomString(16)
pass_cmd = "cat " + serverdir + \
"/data/error.log | grep root@localhost | awk -F 'root@localhost:' '{print $2}'"
passdata = mw.execShell(pass_cmd)
password = passdata[0].strip()
# with mysql_native_password # with mysql_native_password
alter_root_pwd = "flush privileges;\n" alter_root_pwd = "flush privileges;"
alter_root_pwd = alter_root_pwd + \ alter_root_pwd = alter_root_pwd + \
"alter user 'root'@'localhost' identified by '" + pwd + "';" "alter user 'root'@'localhost' identified by '" + pwd + "';"
alter_root_pwd = alter_root_pwd + "flush privileges;"
r = dbcurr.execute(alter_root_pwd) r = dbcurr.execute(alter_root_pwd)
tmp_file = "/tmp/mysql_init_tmp.log"
# mw.writeFile(tmp_file, alter_root_pwd) mw.writeFile(tmp_file, alter_root_pwd)
# cmd_pass = serverdir + '/bin/mysql -uroot -p < ' + tmp_file cmd_pass = serverdir + '/bin/mysql -uroot -p"' + password + '" < ' + tmp_file
# print mw.execShell(cmd_pass) print(cmd_pass)
mw.execShell(cmd_pass)
pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,)) pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,))
return True return True
@ -1842,7 +1847,7 @@ if __name__ == "__main__":
elif func == 'start': elif func == 'start':
print(start(version)) print(start(version))
elif func == 'stop': elif func == 'stop':
print(top(version)) print(stop(version))
elif func == 'restart': elif func == 'restart':
print(restart(version)) print(restart(version))
elif func == 'reload': elif func == 'reload':

Loading…
Cancel
Save