Code: Select all
vesta/func /db.sh
the condition checks if the MySQL version is greater than or equal to 8, but the logic is incorrect.
to fix the bug, we need to correct the conditional statement in the add_mysql_database function.
The correct condition should check if the MySQL version is greater than or equal to 8 or if the
MySQL version is 5 and the sub-version is greater than or equal to 7....
Code: Select all
add_mysql_database() {
mysql_connect $host
mysql_ver_sub=$(echo $mysql_ver | cut -d '.' -f 1)
mysql_ver_sub_sub=$(echo $mysql_ver | cut -d '.' -f 2)
query="CREATE DATABASE \`$database\` CHARACTER SET $charset"
mysql_query "$query" > /dev/null
if [ "$mysql_fork" = "mysql" ] && { [ "$mysql_ver_sub" -ge 8 ] || { [ "$mysql_ver_sub" -eq 5 ] && [ "$mysql_ver_sub_sub" -ge 7 ]; } }; then
query="CREATE USER \`$dbuser\`@\`%\` IDENTIFIED BY '$dbpass'"
mysql_query "$query" > /dev/null
query="CREATE USER \`$dbuser\`@localhost IDENTIFIED BY '$dbpass'"
mysql_query "$query" > /dev/null
query="GRANT ALL ON \`$database\`.* TO \`$dbuser\`@\`%\`"
mysql_query "$query" > /dev/null
query="GRANT ALL ON \`$database\`.* TO \`$dbuser\`@localhost"
mysql_query "$query" > /dev/null
else
query="GRANT ALL ON \`$database\`.* TO \`$dbuser\`@\`%\` IDENTIFIED BY '$dbpass'"
mysql_query "$query" > /dev/null
query="GRANT ALL ON \`$database\`.* TO \`$dbuser\`@localhost IDENTIFIED BY '$dbpass'"
mysql_query "$query" > /dev/null
fi
if [ "$mysql_fork" = "mysql" ]; then
md5=$(mysql_query "SHOW CREATE USER \`$dbuser\`" 2>/dev/null)
md5=$(echo "$md5" | grep password | cut -f 8 -d \')
else
md5=$(mysql_query "SHOW GRANTS FOR \`$dbuser\`" 2>/dev/null)
md5=$(echo "$md5" | grep PASSW | tr ' ' '\n' | tail -n 1 | cut -f 2 -d \')
fi
}