Table of Contents
Here I will write down some frequently used SQL examples , which I happen to search for again and again.
SELECT records from date column before or after a given DAYS
Select all records from a table “some_table” from MORE THANĀ 30 DAYS
select some_field from some_table where some_date <= ( CURDATE() - INTERVAL 30 DAY );
Check mysql users CPU usage
select user,cpu_time from information_schema.user_statistics order by cpu_time;
Working with Tables
Check MySQL table / tables properties
# Show properties for all tables in the current DB show table status \G # Show properties for just one table: some_table show table status like 'some_table' \G
Copy / Duplicate mysql table structure
Suppose you have mysql table called “original_table” and you want to make a copy of it. Here’s the SQL needed:
CREATE TABLE copy_table LIKE original_table;
And if you like also to copy the content of the table:
INSERT copy_table SELECT FROM original_table;