How to get the drupal version using query ? Or how do we detect using query the drupal version is 7,6,5 or 4?

  • This post is relevant however whilst does give you lots of options doesn't actually say how to get this from the DB. – Felix Eve Apr 17 '14 at 8:12

This will work with Drupal 7 - I don't have other version to test it on but think it should work...

Because the version is stored in the text file CHANGELOG.txt we can write that to a table in the DB, read from the table, and then delete it again afterwards:

First run this: (make sure to change the path to your changelog file)

CREATE TABLE `drupal_version` (`data`  varchar(255) NULL);
LOAD DATA INFILE '/var/www/your_site/htdocs/CHANGELOG.txt' INTO TABLE drupal_version;
SELECT * FROM drupal_version WHERE data LIKE "%Drupal%" LIMIT 1;

This will return something like:

Drupal 7.26, 2014-01-15

And run this to delete the table we just made:

DROP TABLE drupal_version;

Whilst this is a long winded way of reading text from a text file it is strictly speaking getting the version using MySQL...

Second Option

As Topsitemakers suggested looking in the system table I had a look and found the version was hidden in there, but only against specific modules. I figured the field module would be in all version of drupal, however I very highly doubt that this query will actually work on any version other that 7 as it's so specific and a bit of a beast:

SELECT MID(info, LOCATE(':"', info, LOCATE('"version";', info)) + 2, MID(info, LOCATE('"version";', info) + 12, LOCATE(':"', info, LOCATE('"version";', info)) - LOCATE('"version";', info) - 12))
FROM system WHERE filename LIKE "%/field.module"

For me this query returns:

  • 3
    Now, this is a smart way to answer to what the OP ASKED. :-) – kiamlaluno Apr 17 '14 at 8:35
  • 4
    This is...hideous!! Kudos for answering the question exactly as it was posed, but I hope the OP knows better than to actually use either of these methods for anything real :) – Clive Apr 17 '14 at 9:21
  • Ha ha ha - hideous... I completely agree :) – Felix Eve Apr 17 '14 at 9:23

Open modules/system/system.info file and check out the value of core item.
The value will tell you the version, e.g. 6.x/7.x/8.x.

  • how to check for drupal version 5,4? – harshal Apr 17 '14 at 8:15
  • 1
    I'm not sure if the version of Drupal even stored in the DB. I just searched the whole db for "version" and nothing promising came up... – Felix Eve Apr 17 '14 at 8:16
  • @harshal AFAIK D4/D5 don't have the core value but have version which will tell you the core info. @FelixEve the information in system table might help; I'm not sure though of its schema in D4 though. – Aram Boyajyan Apr 17 '14 at 8:26

This should work for D7 and D6, i don't have other versions to test but if system table is similar, it should work as well.

SELECT MAX(schema_version) FROM system;

This will get something like "7002" or some number starting with a 7 for Drupal 7 and "6005" or something starting with 6 for Drupal 6. It's not the exact running version but if you just have a database dump you can figure out from where it comes from.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.