Get MySQL Database Size from Terminal

If you need to find out the size of MySQL databases you use from terminal, the following query will list all the databases with their respective sizes:

mysql> SELECT table_schema "database", sum(data_length + index_length)/1024/1024 "size in MB" FROM information_schema.TABLES GROUP BY table_schema;

The result you’ll get will be something like:

| database           | size in MB     |
+--------------------+----------------+
| test1              | 13542.68241349 | 
| test2              |  1522.23837675 | 
| test3              | 26532.27326164 | 
| information_schema |     0.00390626 | 
+--------------------+----------------+
4 rows in set (0.02 sec)

If you have large databases, you can show the result in gigabytes with this query:

mysql> SELECT table_schema "database", sum(data_length + index_length)/1024/1024/1024 "size in GB" FROM information_schema.TABLES GROUP BY table_schema;

If you liked the post, we should get connected - follow me on Twitter

How to run scripts in Linux faster than Cron does

Cron is an amazing job scheduler. But, when it comes to running your scripts in less than every minute, it can’t help.

With Cron, you can run your scripts every minute, but not in shorter period of time.

This problem can be solved with simple bash script. For example, if you need to run a PHP script on every 20 seconds, you can create a bash script like this:

#!/bin/bash
#Name:myscript.sh
#Desc:Run script in every 20 seconds
while (sleep 20 && php /path_to_your_script/your_script_name.php) &
do
 wait $!
done

Then, make script executable, and add it to the system startup. That’s all.

 

 


If you liked the post, we should get connected - follow me on Twitter

Linux gets frozen, what do you do?

Somehow, you crashed your Linux. It’s completely frozen. You try pressing Ctrl + Alt + Backspace, but doesn’t help.

What to do? Someone would press the power button and restart or shut down the system. You shouldn’t do this. This can make you a lot of problems.

 

What you can do, is to perform a gentle Linux restart.  This is much safer way to restart your frozen Linux.  To do this, you need to press:

Ctrl + Alt + PrtSc (SysRq) + reisub

Just to make it clear. You need to press and hold Ctrl, Alt and PrtSc(SysRq) buttons, and while holding them, you need to press r, e, i, s, u, b

This will restart your Linux safely.

It’s possible that you’ll have problem to reach all the buttons you need to press. I’ve seen people type reisub with their nose :)

So, here’s my suggestion: With your smallest finger on the left hand, press Ctrl. With your thumb on left hand, press Alt. With the smallest finger on your right hand press PrtSc(SysRq) button. This way, you’ll be able to access to reisub buttons with your other fingers.

Okay, but what this REISUB means? 

  • R: Switch the keyboard from raw mode to XLATE mode
  • E: Send the SIGTERM signal to all processes except init
  • I: Send the SIGKILL signal to all processes except init
  • S: Sync all mounted filesystems
  • U: Remount all mounted filesystems in read-only mode
  • B: Immediately reboot the system, without unmounting partitions or syncing

You can find the complete list here. There you can see that shuts down the system. So, if you want to turn off your PC when your Linux crash, you can use this combination:

Ctrl + Alt + PrtSc (SysRq) + reisuo


If you liked the post, we should get connected - follow me on Twitter

Test Download Speed From Console

If you sometimes need to check download speed on a remote computer, to which you are connected through console, here is a nice tip how to do this:

 wget http://cachefly.cachefly.net/100mb.test 

Yes, simple as that. Download a 100 MB test file using wget, and you’ll see a download speed in console.


If you liked the post, we should get connected - follow me on Twitter

3 Twitter Search Ideas You (Probably) Don’t Know About

Last few days I was working on developing simple Twitter console client in Perl, and I got some interesting results while playing with Twitter search.

Have you ever thought that you can find some ideas for startup on Twitter? Well, if you try searching for:

"should invent"

you can get some pretty interesting results, and if you search for a while, you can even get some cool ideas.

 

Another interesting point. Since lots of people are sharing their emails in tweets, Twitter search can be a nice source for spammers. Try searching for:

"email me at"
"email me on"
"email me to"

You’ll get lots of emails. I even wrote a simple Perl script to download all those tweets, and parse the emails into a text file. Quite an easy way to get some emails.

 

And the last one I will share today. If you are looking for a job, you can find a lot of job offers. Try searching for “jobs <country|city> <keyword>”. Here are few examples:

jobs uk
jobs usa linux
I'm hiring london

That’s it for now. Happy tweeting ;)

 


If you liked the post, we should get connected - follow me on Twitter