Friday, April 1, 2016

How to show MySQL version in query

If you want and you needed, you can get information about mysql version from within your mysql query, in this article i will show you how to do that.

On mysql there is a system variable that specifically design for retrieving information about mysql version, we can put this variable inside our query if needed.
SELECT @@version
SELECT @@version as mysql_version
SELECT email, username, @@version from users

Besides @@version, there are also similar variable for retrieving version information, such as @@version_comment, @@version_compile_machine, @@version_compile_os.

SELECT @@version
SELECT @@version_comment
SELECT @@version_compile_machine
SELECT @@version_compile_os

The @@version_comment will display the operating system name, since i'm using ubuntu, it shows (Ubuntu). The @@version_compile_machine will display what kind of operating system you have 64 bit or 32 bit.

If you have 64 bit it should display x86_64, other than that, your operating system must be 32 bit, lastly the @@version_compile_os will display the operating system origin, which in my case 'debian-linux-gnu' because ubuntu is derived from debian.

The @@version variable is one of the most useful feature of mysql specially for sql injection, hackers often used this for getting information about the mysql server version. After getting the version they can look for weakness or any known bugs on the version.

No comments:

Post a Comment