diff --git a/plugins/mariadb/index.py b/plugins/mariadb/index.py index 93c457172..4c820c4b6 100755 --- a/plugins/mariadb/index.py +++ b/plugins/mariadb/index.py @@ -363,20 +363,26 @@ def initMariaDbPwd(): print("init mariadb password fail:" + data[1]) exit(1) + # 删除空账户 + drop_empty_user = serverdir + '/bin/mysql ' + db_option + '-uroot -p' + \ + pwd + ' -e "use mysql;delete from user where USER=\'\'"' + mw.execShell(drop_empty_user) + # 删除测试数据库 drop_test_db = serverdir + '/bin/mysql ' + db_option + ' -uroot -p' + \ pwd + ' -e "drop database test";' mw.execShell(drop_test_db) # 删除冗余账户 - hostname = mw.execShell('hostname')[0].strip() - drop_hostname = serverdir + '/bin/mysql --defaults-file=' + \ - myconf + ' -uroot -p' + pwd + ' -e "drop user \'\'@\'' + hostname + '\'";' - mw.execShell(drop_hostname) - - drop_root_hostname = serverdir + '/bin/mysql --defaults-file=' + \ - myconf + ' -uroot -p' + pwd + ' -e "drop user \'root\'@\'' + hostname + '\'";' - mw.execShell(drop_root_hostname) + if hostname != 'hostname': + hostname = mw.execShell('hostname')[0].strip() + drop_hostname = serverdir + '/bin/mysql --defaults-file=' + \ + myconf + ' -uroot -p' + pwd + ' -e "drop user \'\'@\'' + hostname + '\'";' + mw.execShell(drop_hostname) + + drop_root_hostname = serverdir + '/bin/mysql --defaults-file=' + \ + myconf + ' -uroot -p' + pwd + ' -e "drop user \'root\'@\'' + hostname + '\'";' + mw.execShell(drop_root_hostname) pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,)) return True diff --git a/plugins/mysql-apt/index.py b/plugins/mysql-apt/index.py index 8b77ba3ed..a1b67874e 100755 --- a/plugins/mysql-apt/index.py +++ b/plugins/mysql-apt/index.py @@ -345,16 +345,16 @@ def initMysql8Pwd(): # 删除冗余账户 hostname = mw.execShell('hostname')[0].strip() + if hostname != 'localhost': + drop_hostname = cmd_my + ' --defaults-file=' + \ + myconf + ' -uroot -p' + pwd + ' -e "drop user \'\'@\'' + hostname + '\'";' + mw.execShell(drop_hostname) - drop_hostname = cmd_my + ' --defaults-file=' + \ - myconf + ' -uroot -p' + pwd + ' -e "drop user \'\'@\'' + hostname + '\'";' - mw.execShell(drop_hostname) + drop_root_hostname = cmd_my + ' --defaults-file=' + \ + myconf + ' -uroot -p' + pwd + ' -e "drop user \'root\'@\'' + hostname + '\'";' + mw.execShell(drop_root_hostname) - drop_root_hostname = cmd_my + ' --defaults-file=' + \ - myconf + ' -uroot -p' + pwd + ' -e "drop user \'root\'@\'' + hostname + '\'";' - mw.execShell(drop_root_hostname) - - pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,)) + pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,)) return True diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 20f8d24a7..5123c0776 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -428,14 +428,14 @@ def initMysqlPwd(): # 删除冗余账户 hostname = mw.execShell('hostname')[0].strip() - - drop_hostname = serverdir + '/bin/mysql --defaults-file=' + \ - myconf + ' -uroot -p' + pwd + ' -e "drop user \'\'@\'' + hostname + '\'";' - mw.execShell(drop_hostname) - - drop_root_hostname = serverdir + '/bin/mysql --defaults-file=' + \ - myconf + ' -uroot -p' + pwd + ' -e "drop user \'root\'@\'' + hostname + '\'";' - mw.execShell(drop_root_hostname) + if hostname != 'hostname': + drop_hostname = serverdir + '/bin/mysql --defaults-file=' + \ + myconf + ' -uroot -p' + pwd + ' -e "drop user \'\'@\'' + hostname + '\'";' + mw.execShell(drop_hostname) + + drop_root_hostname = serverdir + '/bin/mysql --defaults-file=' + \ + myconf + ' -uroot -p' + pwd + ' -e "drop user \'root\'@\'' + hostname + '\'";' + mw.execShell(drop_root_hostname) pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,)) return True