Repairing Drupal site blocks manually in database

  • Post author:
  • Post last modified:May 12, 2022
  • Reading time:2 mins read

The text format of a block was PHP code and it contained PHP code with an error. This broke the website resulting in blank screen web pages, the white screen of death (WSOD). The error was rectified by manually updating the MySQL database. The following steps were taken.

From the command line, connect with the website database,

$ mysql -u website-drupal-user -p 
mysql> show databases;
mysql> use website-drupal-database;
mysql> show tables;

The show tables command gives a list of all MySQL tables in the website database.

mysql> show tables;
+-----------------------------------------+
| Tables_in_drupal7                       |
+-----------------------------------------+
| accesslog                               |
| actions                                 |
| advanced_help_index                     |
| aggregator_category                     |
| aggregator_category_feed                |
| aggregator_category_item                |
| aggregator_feed                         |
| aggregator_item                         |
| authmap                                 |
| batch                                   |
| block                                   |
| block_custom                            |
| block_node_type                         |
| block_role                              |
| blocked_ips                             |
| cache                                   |
....

The table block_custom is of interest to us as we wish to repair one of the blocks created recently. We can see the columns of block_custom,

mysql> describe block_custom;
+--------+------------------+------+-----+---------+----------------+
| Field  | Type             | Null | Key | Default | Extra          |
+--------+------------------+------+-----+---------+----------------+
| bid    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| body   | longtext         | YES  |     | NULL    |                |
| info   | varchar(128)     | NO   | UNI |         |                |
| format | varchar(255)     | YES  |     | NULL    |                |
+--------+------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

The attribute info is the block name and format is the text format. The text format of the concerned block (block-name, as shown in the example below and to be replaced by the actual name of the block) is updated by the command,

mysql> update block_custom set format="full_html" where info="block-name";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> quit

After the above update, the web pages are displayed and the block text can be edited via the Administration menu Structure -> Blocks option.

Share

Karunesh Johri

Software developer, working with C and Linux.