You don't need the .*
inside the capturing group (or the semicolon at the end of line):
db="$(sed -n 's/.*DB_USERNAME *= *\([^ ]*\).*/\1/p' < config.ini)"
To elaborate:
.*
matches anything at allDB_USERNAME
matches that literal string*
(a single space followed by an asterisk) matches any number of spaces=
matches that literal string*
(a single space followed by an asterisk) matches any number of spaces\(
starts the capturing group that is used for\1
later[^ ]
matches anything which is not a space character*
repeats that zero or more times
\)
ends the capturing group.*
matches anything at all
Therefore, the result will be all the characters after DB_USERNAME =
and any number of spaces, up to the next space or end of line, whichever comes first.