Tyler Frankenstein's Drupal Association Membership Tyler Frankenstein GItHub Link


MySQL - Drop All Tables In a Database

Sometimes you may not have sufficient privileges to be able to just DROP an entire database on a MySQL server. In that case, you may be able to just drop each table in the database instead. If you have one or two tables, it is easy enough to just type the 'drop table' command from a MySQL terminal, but if you have dozens and dozens of tables, this will get tedious fast. Here is a nice terminal command to drop all the tables in a database when you don't have permission to drop the database itself:

Drupal - File Usage MySQL Queries

Here are a few helpful MySQL queries to retrieve file usage in Drupal (perhaps via IMCE or other file management module).

Total File Space Used by a Particular User

select SUM(filesize) as total_space from {files} where uid = 123;

Total File Space Used by a Particular Directory

select sum(filesize) as total_size from {files} where filepath like '%files\/my_sub_dir\/my_other_sub_dir%';

Drupal - How to Make a Backup Copy of MySQL Database

Here is how you can make a backup copy of your Drupal's MySQL database from a terminal:

mysqldump -u my_drupal_mysql_uer_name -p my_drupal_mysql_database_name > ~/my_drupal_sql_dump.sql

I like to clear all of Drupal's caches before running the dump so there isn't a bunch of cache data in the export.

If you'd prefer to use Drush, check out this article instead: Use Drush to Export/Import a Drupal MySQL Database Dump File

Use Drush to Export/Import a Drupal MySQL Database Dump File

Export Database to File

So today I wanted to learn how to export a Drupal database to a file quickly. Back in the day I would've logged in through cPanel and navigated to PHPMyAdmin, then manually select an export of the database and have to choose where to save the file. Not to mention all the previous steps listed would need to be preceeded by a Drupal cache flush (I don't like the cache inside a database backup). Typically this would've taken me about 5 minutes to complete, well my friends, no longer is that the case.

Subscribe to RSS - mysql