Skip to main content

Using Drush to run SQL commands

To run a SQL command using Drush, use the following sql-query command

drush sql-query "COMMAND"

As an example, in the following I will remove all of the records in the Watchdog.

 

Delete from watchdog

To empty (clear) the watchdog table, which contains Drupal's log messages, using the above noted command. The command to delete all entries from the watchdog table is as follows:

Drupal 9 to 10 upgrade an example of the actual steps taken

 

Continuing on from the Drupal 9 to Drupal 10 upgrade outline written earlier... Upgrading Drupal 9 to Drupal 10.  However, the point of difference is this article works through the actual action steps of the upgrade.

Planning and testing is critical for the Drupal to version 10 process to work successfully.  As some of the environments that I work in are deployed via CD/CI pipelines.

Drupal set the private folder

How to set the Private file path in Drupal using the following steps:

  • Create a private folder in the web root
  • Add a .htaccess file to the private folder
  • Update the settings.php file

 

Exporting a MySQL table to a file

Goal: I want to download a table list to a txt or csv file.

Initially, as a root user I tried using drush

drush sql-dump --tables-list=media_field_data > db-list.sql

Of course as a root user and Drush set-up not as root. failed with 

Command 'drush' not found, did you mean:

  command 'rush' from deb rush (1.8+dfsg-1.1)

My bad.

mysql dump FLUSH TABLES access denied

I've recently upgraded the server Ubuntu 20.04 updating the PHP version from 7.4 to 8.1.  However, when I've attempted to export the MySQL database using the command

drush sql-dump --extra-dump=--no-tablespaces --result-file=../sql/db-2023-02-25.sql

I seeing the following response

Drupal: how to import the configuration on a different site

After cloning a site, next you will want to import the config file.  Which you can do so by running the command:

drush cim -y

Hopefully it worked for you.  As it didn't work out so well for me as the response was:

Drush a few common commands to import and reset

Working through and importing JSON data into a content type.

 

Drush migration commands

Check the status of the migration data

lando drush migrate-status

Reset the migration status 

lando drush migrate-reset-status  migratable_riverdata_json

Import JSON data

CLI using drush to drop tables in your db and reload

This is a relatively quick process, beginning with dropping the database tables

lando drush sql-drop -y

Import a MySQL database

lando db-import {filename}

such as 

lando db-import riverdev.2022-10-03-1664769553.sql.gz

Rebuild cache

lando drush cr

Finally, export your config

Subscribe to Drush