How to get server MySQL version in PHP without connecting

If you have access to the command line mysql executable you can try this:

function getMySQLVersion() { 
  $output = shell_exec('mysql -V'); 
  preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); 
  return $version[0]; 
}

For the client version:

print mysql_get_client_info();

Without shell access to get the server version you must connect first:

$link = mysql_connect("localhost", "username", "password");
if (!$link) die('Could not connect: ' . mysql_error());
print "MySQL server version: " . mysql_get_server_info();
mysql_close($link);

You'll need the user to enter their DB credentials, so you can connect to the MySQL server and run the following query to get the MySQL server version:

SHOW VARIABLES LIKE 'version'

Here's the output on my server:

Variable_name     Value
----------------------------
version           5.1.53-log

Tags:

Mysql

Php