If you need to manually disable a module you can do so in the database. Before you start, do a mysqldump (or export) of your Drupal db to a local file in case things go wrong and you need to roll back.

Accessing MySQL

In order to perform these commands one must have access and proper permissions to execute MySQL commands. These commands can be executed with GUI like phpMyAdmin, or just the MySQL command line interface.

phpMyAdmin

To disable a module via phpMyAdmin you must login to phpMyAdmin. Then you must locate the database where Drupal is installed. Once you have done so look for the "system" table (Drupal7), "config" table (Drupal8). Click and open it. Click to browse the table. Find the record for the module that is causing the problems and select the edit function. Set the status to "0" and save.

MySQL command line

To disable a module using the MySQL command line, run the following SELECT to look at the state of your data before the change. This will help you to find the full name of the module too.

MySQL Commands Drupal 7

See all the modules that have been installed enabled or not:
SELECT name,status FROM system WHERE type='module';

See all the modules enabled:
SELECT name,status FROM system WHERE type='module' AND status='1';

See if a particular module is enabled:
SELECT name,status FROM system WHERE name='module_name';

Disable your module, set the status to 0 for the module name that you want to disable.
UPDATE system SET status='0' WHERE name='module_name';

Enable your module:
UPDATE system SET status='1' WHERE name='module_name';

Check your handiwork using the SELECT statement again.

MySQL Commands Drupal 8

Use Mysql Table "config" instead of "system", f. ex.:

See all the modules that have been installed enabled or not:
SELECT name,status FROM config WHERE type='module';

MySQL Commands Drupal 9

First see if the module is installed:
SELECT * FROM `key_value` WHERE name = 'module_name'

Then remove the module with:
DELETE FROM `key_value` WHERE name = 'module_name'

Drupal 7: Clear Cached System List

On Drupal 7, you must still follow the procedure above to disable the module in the system table. However, data from the system table is cached. This means that even though you updated the system table, Drupal may still think the module is enabled because its cached copy of the system table is not up-to-date.

The cached copy of the system list is in the cache_bootstrap table. Clear the cached copy of the system list as follows.

phpMyAdmin

If you are using phpMyAdmin, find the "cache_bootstrap" table, and delete the record with cid="system_list".

MySQL Command Line

To update the cache using the mysql command line, type:
DELETE FROM cache_bootstrap WHERE cid='system_list';

Using DRUSH on Drupal 9

If Drush not yet installed then you can install Drush using:
composer require drush/drush

Then execute below command:

drush eval "\$module_data = \Drupal::config('core.extension')->get('module'); unset(\$module_data['MODULE_NAME']); \Drupal::configFactory()->getEditable('core.extension')->set('module', \$module_data)->save();"

Comments

toreki’s picture

I disabled my broken module in 6.x with replace the .module file to blank file. After this, I disabled it on /admin/build/modules page.

featherbelly’s picture

Use something like this:

UPDATE `system` SET `status`='0' WHERE `filename` LIKE '%sites/all%' AND `type ='module' AND `status` ='1';

replaces 'sites/all' with the path to your contrib/site modules folder.

miststudent2011’s picture

UPDATE `system` SET `status` = '0' WHERE `system`.`filename` = 'sites/all/modules/custom/module_name/module_name.module';

Works for me on Mysql for Drupal 6

brayo4’s picture

UPDATE databasename.system SET status=0, throttle=-1 WHERE
(filename LIKE 'sites/all/modules%' ) AND status=1 AND type='module'

replace the database name with your own dbase name.
thanks to stanford.edu

Trollargh’s picture

The core module "update manager" somehow got disabled on a drupal site I was working on and the checkbox was grayed out, so I could not check it. So I went trough the steps mentioned above. I did it manually with phpMyAdmin - the name field in the system table was simply called "update". I set the status to 1 and then deleted the "system_list"record in "cache_bootstrap".

The update manager was working again. But when I looked under modules, I mentioned the red text saying "disabled". The checkbox was checked and it was clearly working.

This is not a big problem, but somehow disturbing me. Does anyone know how to fix it?

pimok3000’s picture

SELECT name,status FROM system WHERE type='module' AND status='1';

akki123’s picture

Disable your module, set the status to 0 for the module name that you want to disable.
Set schema_version to -1 to uninstall a module so that it will not appear on admin/modules/uninstall page
UPDATE system SET status='0', schema_version='-1' WHERE name='module_name';

akki

humansky’s picture

I'm assuming this method doesn't call hook_install() and hook_uninstall(). Is that correct?

holingpoon’s picture

Yes, your assumption is correct. The method described in this node involves direct manipulation of the database. So, for example, unlike hook_install() and hook_uninstall(), this does not create or drop the field_revision tables.

Anonymous’s picture

magnus_n’s picture

I think I misread this guide and accidentally deleted the column 'cid'..
is there a way to create a new one?
This is the code Phpmyadmin wants me to use:
ALTER TABLE `cache_bootstrap` ADD `cid` VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'Primary Key: Unique cache ID.' AFTER , ADD PRIMARY KEY (`cid`);

but it won't let me create it

mistermastermatt’s picture

I needed to disable a module and I followed the steps detailed on this page - including the clearing of the cache table, but with no joy. I still think it was some kind of cache problem however as when I then updated the database via update.php I had success. nb. I had 500 errors everywhere except update.php.
Thanks for the info on this page - it was very useful.

amolranjegaonkar’s picture

For Druapl 8, Try removing the module from your module folder and run rebuild.php

johannzs’s picture

Thanks a lot! It worked all fine for me.

Mike Dodd’s picture

Perfect, worked for me

If Windows is the answer, it must have been a stupid question. -- Filip Van Raemdonck

hockey2112’s picture

Worked for me as well, thanks!

urix’s picture

D9, worked for me, thanks.
Also helps search and delete all entries, containing module name in MYSQL database, excluding one field - `core.extension` in `config` table.

angelgarciaco’s picture

Well.. It not works for me to run rebuild.php .. so I proceeded to remove module with rm -Rf and ran the command: drush cache-rebuild.. and .. Eureka!! .. It Works!!

frozen10’s picture

I am running postgres db and need to see the list of enabled modules and enable one if necessary directly in the db. I see the commands for mysql or phpadmin. How do you do this on postgres db?

srikanth.g’s picture

Perfectly worked for me "SELECT * FROM system WHERE type='module' AND status='1';"
but don't forget to execute clear cache sql after updating status='0'

SivaprasadC’s picture

Perfectly working.

smurfxx’s picture

I'm testing the latest Drupal 9 release to understand how to use it without composer and drush: I can use composer to download locally some libraries and the transfer them via FTP to my host but how can I disable a module if I don't have drush installed?
Will Drupal 9 be banned for shared hosting?

wasare’s picture

@smurfxx you can uninstall as usual on admin area: admin/modules/uninstall

smurfxx’s picture

Disabling modules from the database is an emergency procedure, I know I can disable them from UI but if a module has a broken dependency the entire drupal 9 site is blocked (like enabling devel module on drupal 9, it breaks everything). So, if the site is not working, I can't do a direct query to disable the indicted module and I'm on a shared hosting what could I do? Specially if the site is on production?

wasare’s picture

First of all check your hosting logs. If you have some developer skill you could include the PHP code into any module inside hook_preprocess_HOOK():

/**
 * Implements hook_preprocess_HOOK().
 */
function MODULE_NAME_preprocess_page(&$variables) {
  $module_data = \Drupal::config('core.extension')->get('module'); 
  unset($module_data['module_name_to_fix']);
  \Drupal::configFactory()->getEditable('core.extension')->set('module', $module_data)->save();
}

Alternatively you could always keep your system health. See this module to deal with most common issues: https://www.drupal.org/project/easy_install

Matter of fact if is when your production site broken probably had lacked of tests in dev environment (often is that the main reason).

wasare’s picture

You could do a direct query in your database too. Use a db manager like PHPMyAdmin. All shared hosts provides that tool.

roaashattnawi’s picture

did you find solution for this error ?

jyoti_drupal’s picture

As mentioned above
"MySQL Commands Drupal 9
Use Mysql Table "key_value" and look for field "name". Change BLOB-Data."
Can someone explain more about this?

bmunslow’s picture

This expands a bit further on how to manually enable / disable a module in the database in Drupal 9 with the actual queries you need to run.

Replace 'my_module' with the actual machine name of the module you are trying to install or uninstall.

In order to install a module:
INSERT INTO key_value (collection, name, value) VALUES ('system.schema', 'my_module', CAST('my_module' AS BINARY))

In order to uninstall a module:
DELETE FROM key_value WHERE name = 'my_module'

jaesperanza’s picture

For those who would attempt to run a composer uninstall, beware it will break the site on D9, you may use drush pm-uninstall module_name instead

bkline’s picture

@bmunslow Do you perhaps mean DELETE FROM (rather than REMOVE FROM)?

bmunslow’s picture

Yes indeed, thanks for the heads-up, fixed!

goose2000’s picture

I tried the DB method for D9 for the RDF module (it was set to enabled from the start). But it still shows enabled ?

MySQL Commands Drupal 9
First see if the module is installed:
SELECT * FROM `key_value` WHERE name = 'rdf'

Than remove the module with:
DELETE FROM `key_value` WHERE name = 'rdf'

I was sure to clear all cache and run update.php
Any other ideas? Thanks

cestmoi’s picture

None of the tips seems to apply to Drupal 10. Any ?

SivaprasadC’s picture

In my case on D10 site, Deleted entries with the below commands and ran https://yoursite/rebuild.php in the browser.

First see if the module is installed:
SELECT * FROM `key_value` WHERE name = 'module_name'

Than remove the module with:
DELETE FROM `key_value` WHERE name = 'module_name'