Programmer’s Reference

1458 views

MySQL

Put the MySQL server into read-only mode:

FLUSH TABLES WITH READ LOCK;
SET GLOBAL read_only = 1;

Take server out of read-only mode:

SET GLOBAL read_only = 0;
UNLOCK TABLES;

Check active MySQL processes:

show processlist;

List all databases along with their sizes in megabytes:

SELECT table_schema "Database",
    sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",
    sum( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ;

Ubuntu Administration

Check free disk space:

df -h

Find the total size (in kilobytes) of all files not accessed in the last 150 days:

find /directory/  -atime +150 -type f  -print0 | xargs -r0 du -a| awk '{sum+=$1} END {print sum}'

Rsync

Sync local server using the remote server as master, deleting local files that are non-existent in remote server:

rsync -avzP --delete -e 'ssh -p SSHPORTHERE'  root@SERVERIPHERE:/remotedirpath/ /localpath

WordPress

Delete all empty categories with SQL:

DELETE a,c
FROM
	DATABASENAME.wp_terms AS a
	LEFT JOIN DATABASENAME.wp_term_taxonomy AS c ON a.term_id = c.term_id
	LEFT JOIN DATABASENAME.wp_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE (
	c.taxonomy = 'category' AND
	c.count = 0
	)

Windows Command Line

Append a string (_my_string_) to the end of the name of each png file in a folder:

for %a in (*.png) do ren "%~a" "%~na_my_string_%~xa"
Commenting rules: Politeness is the only rule. We respect your right to disagree with anything we say. But comments with profanity and insults will be deleted.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
My work is made possible by your kind donations. Donate securely via Stripe (no registration required):