Find out MySQL version without the database details?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Find out MySQL version without the database details?

Post by kaisellgren »

Hi,

Does anyone have a solution to find out the installed MySQL version without the connection details? Maybe by reading some specific files?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Find out MySQL version without the database details?

Post by requinix »

Can always do

Code: Select all

$ mysqld --version
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Find out MySQL version without the database details?

Post by mikemike »

If you have commandline/SSH access you can just do `mysql -V`

Code: Select all

[root@mike-hub httpdocs]# mysql -V
mysql  Ver 14.12 Distrib 5.0.45, for redhat-linux-gnu (x86_64) using readline 5.0
User avatar
iFlex
Forum Commoner
Posts: 41
Joined: Sat May 30, 2009 3:44 am

Re: Find out MySQL version without the database details?

Post by iFlex »

Code: Select all

<?php
 
//Call to discover PHP information on your server.
phpinfo();
 
?>
 
Should do the trick, just search for the MySQL bit.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Find out MySQL version without the database details?

Post by McInfo »

This is a pretty dirty way of doing it, but it works on Windows and should work on Unix.

Code: Select all

<?php
function get_mysql_version ()
{
    ob_start();
    phpinfo(INFO_MODULES);
    preg_match('#<td class="e">Client API version </td><td class="v">([0-9.]+) </td>#', ob_get_contents(), $matches);
    ob_end_clean();
    return isset($matches[1]) ? $matches[1] : false;
}
echo 'MySQL Version: '.get_mysql_version();
?>
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Tue Jun 15, 2010 10:08 pm, edited 1 time in total.
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: Find out MySQL version without the database details?

Post by kaisellgren »

It was simpler then I thought: mysqli_get_client_info(); :D
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Find out MySQL version without the database details?

Post by McInfo »

I overlooked that one because I saw that both mysql_get_host_info() and mysql_get_server_info() have a link resource parameter. Haste makes waste, I guess.

Edit: This post was recovered from search engine cache.
Post Reply