Skip to content

Commit c1cbbd3

Browse files
authored
Fix for mysql 5.7 when reset password
Whit mysql 5.7 when reset password db.conf not get updated because cant get new md5 hash This will fix it I not touch GRANT ALL queryes because all working fine whit that part and all passwords was changed, but maybe you want change it. I see this bug may afect this function: dump_mysql_database() But I not know fot what is used grep -v "Grants for" > $grants So I not touch it because not know how test it :)
1 parent 04d617d commit c1cbbd3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

func/db.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,15 @@ change_mysql_password() {
263263
query="GRANT ALL ON \`$database\`.* TO \`$DBUSER\`@localhost
264264
IDENTIFIED BY '$dbpass'"
265265
mysql_query "$query" > /dev/null
266-
267-
query="SHOW GRANTS FOR '$DBUSER'"
268-
md5=$(mysql_query "$query" 2>/dev/null)
269-
md5=$(echo "$md5" |grep 'PASSWORD' |tr ' ' '\n' |tail -n1 |cut -f 2 -d \')
266+
267+
if [ "$(echo $mysql_ver |cut -d '.' -f2)" -ge 7 ]; then
268+
269+
md5=$(mysql_query "SHOW CREATE USER \`$DBUSER\`" 2>/dev/null)
270+
md5=$(echo "$md5" |grep password |cut -f8 -d \')
271+
else
272+
md5=$(mysql_query "SHOW GRANTS FOR \`$DBUSER\`" 2>/dev/null)
273+
md5=$(echo "$md5" |grep PASSW|tr ' ' '\n' |tail -n1 |cut -f 2 -d \')
274+
fi
270275
}
271276

272277
# Change PostgreSQL database password

0 commit comments

Comments
 (0)