try to find the MySQL basedir using mysql_config if it is available

fall back to good old /usr if mysql_config is not installed

thanks @sttts for the idea
try really hard to compute an md5 sum of a random string

I never thought this could bit THAT complicated.
find free port using either ss (iproute2) or nc (netcat)