+# Try to match default version, otherwise just take the first version
+# that matches
+.if !empty(_WANT_MYSQL_VER)
+. for version in ${_WANT_MYSQL_VER}
+. if ${MYSQL_DEFAULT} == ${version}
+MYSQL_VER= ${version}
+. endif
+MYSQL_VER?= ${version}
+. endfor
+.endif
+# Derive MySQL flavour from version
+.if !empty(${MYSQL_VER:M[0-9.]*m})
+MYSQL_FLAVOUR= MariaDB
+.elif !empty(${MYSQL_VER:M[0-9.]*p})
+MYSQL_FLAVOUR= Percona
+.else
+MYSQL_FLAVOUR= MySQL
+.endif
+# Now we can generate a proper message
+.if !empty(_WANT_MYSQL_VER)
+. if defined(_MYSQL_VER) && ${_MYSQL_VER} != ${MYSQL_VER}
+IGNORE?= cannot install: the port wants ${MYSQL_FLAVOUR}-client version ${_WANT_MYSQL_VER} and you have ${_MYSQL_FLAVOUR} version ${_MYSQL_VER} installed
+. endif
+.endif
+
+# OK, so the port is ambivalent, we'll just take what's on the system.
+MYSQL_VER?= ${_MYSQL_VER}
+MYSQL_FLAVOUR?= ${_MYSQL_FLAVOUR}
+
+# After all that, we still have found nothing!
+.if empty(MYSQL_VER)
+MYSQL_VER= ${MYSQL_DEFAULT}
+MYSQL_FLAVOUR= MySQL
+.endif
+
+# We don't want to be :S,.,, the whole time when doing port version checks
+MYSQL_VER_NODOT= ${MYSQL_VER:S,.,,}
+
+# And now we are checking if we can use it
+.if defined(MYSQL${MYSQL_VER_NODOT}_LIBVER)
+# Compat. Please DO NOT use IGNORE_WITH_MYSQL!
+. if defined(IGNORE_WITH_MYSQL)
+DEV_WARNING+= "Do not set IGNORE_WITH_MYSQL, use the version argument to USES=mysql"
+. for ver in ${IGNORE_WITH_MYSQL}
+. if (${MYSQL_VER} == ${ver})
+IGNORE?= cannot install: does not work with ${_MYSQL_FLAVOUR:tl}${MYSQL_VER_NODOT:C/[mp//]}-client (${_MYSQL_FLAVOUR} ${IGNORE_WITH_MYSQL} not supported)