query

MySQL – Search for tables by column name

Solution

SELECT DISTINCT TABLE_NAME 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%name%'
    AND TABLE_SCHEMA = 'my_database';

 

MySQL Query – Export result to CSV

Solution

mysql -u user -p pass -B -e "SELECT * FROM blog_post WHERE title LIKE '%MySQL%'" > output_file.csv

 

How to see how much disk space a MySQL table is taking up?

Solution

SELECT
    table_schema as `Database`,
    table_name AS `Table`, 
    ROUND(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES 
ORDER BY (data_length + index_length) DESC;

 

MySQL Query – Disable cache

Solution

Add SQL_NO_CACHE right after SELECT in any query. E.g.:

SELECT SQL_NO_CACHE * FROM post WHERE post.title LIKE '%MySQL%'