An alternative way to check mySQL version in the Magento check script
Magento, like most other open source softwares, provides a list of requirements which need to be fulfilled before it can be installed on your machine. If you are installing Magento for the first time then I would recommend that you read the server requirments. on the other hand there may be some who would like to know which server requirements are fulfilled by their server so that they can see at a glance what they need to ask their hosting providers to install/setup for them.
Magento provides a script for this purpose which can be viewed on this page. You can download the actual script from here. Unzip the downloaded zip file and you will see a PHP script. Copy the script to the location where you would like to install Magento and execute it.
Once executed you will see the output on the page as follows:
The above snap shot shows that the mySQL version installed does not fulfill the version which is funny as we have mySQL community version 5.1 installed which is more than what is required. I looked through the code and found the following code on line 30 which checks the mySQL version
preg_match('/[0-9]\.[0-9]+\.[0-9]+/', shell_exec('mysql -V'), $version);
Note:The shell_exec() command is not allowed on shared hosting servers as it could allow a coder to run code which may compromise the security and stability of the server.
This could be the reason why the $version was coming up empty and due to this the script was flagging that the mySQL version was incompatible. The shell_exec() command may run correctly on some computers but it did not run as expected on ours so I thought of altering it to show the correct mySQL version.
mySQL provides a function mysql_get_server_info() which returns the mySQL version number. The only thing it needs is a connection to be opened to mySQL so it could then return the information. I commented out line 30 and added the following lines of code:
$conn = mysql_connect('server','username','password'); preg_match('/[0-9]\.[0-9]+\.[0-9]+/', mysql_get_server_info(), $version);
You should know the details to connect to your mySQL server for the above to work. After making the above changes I ran the script again and this time it gave the following output:
Please note that the shell_exec() is not wrong but it does not work on some servers due to restrictions. The method I have provided is a workaround should the first method not work.