Click Technology Limited

Linux, Windows, Macs – it's all good!

Output a MySQL result set to a .csv file

October15

This is quite sweet. You need to get some table data straight out to a CSV for manipulating in OpenOffice Calc, or similar products. But how?

Connect to your SQL server using a command line, ususally

mysql -u root -p

enter your password. Show your databases using

SHOW DATABASES;

Switch to your database using

USE my_database_name;

Now show your tables if you like..

SHOW TABLES;

Now get your CSV out from the table results of a query thus..

SELECT Name, Surname, Address, Postcode, Telephone
FROM Customers
INTO OUTFILE '/tmp/customers.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';

Et voila, data dumped to /tmp/customers.csv! Nice.

 

Perhaps my favourite XKCD cartoon.

Perhaps my favourite XKCD cartoon from xkcd.com

OK, funny / cool but how do I get .CSV file to my PC?

Understood.  I use Linux Mint, but in any Debian, Ubuntu, Mint system, open your file manager (or Thunar in Mint-speak) and put

sftp://your_username@your.server.name.com/tmp/

Enter any password required for the target server and voilà, you’re on the /tmp directory on the target server!  From there, you can copy / paste the file as you wish,

posted under Linux Tips | No Comments »

Extract data from a photo

October3

All pictures taken with digital cameras add information to images they take. A lot of information. To see it, install imagemagick using this command on the command line..

sudo apt-get install imagemagick

Then, just use the identify command thus..

identify -verbose /home/me/pics/some_picture.jpg

and it should pump out a heap of data.

Personally, if ever uploading photos to the internet (never) or emailing them to friends (rarely), I make sure to strip all the data from them. For this, use mogrify, also from the imagemagick suite…

mogrify -strip /home/me/pics/some_picture.jpg

Now the exif data has been removed. Nice!

 

True dat..

posted under Linux Tips | No Comments »

Start a VirtualBox server in headless mode

October2

Sometimes (in fact, why not every time?), you will want to start a server on your machine but not have it display a console. In other words, start it ‘headless’.

First, list all your machines. From the command prompt…

VBoxManage list vms

You get a list of all the machine images thus..

"Windows XP" {f0e63449-61bc-40e1-a82f-5a9bc6fb2434}
"Debian Basic" {b596b383-04e7-4895-bfaf-94a206f66960}
"Homestead_default_1407795525403_97441" {7abc2b40-5f57-4a6f-a647-8583c8790a62}
"UDA" {68999d0c-6391-4792-b13a-c120649ab240}
"PXE Boot" {fe1480eb-68d1-493a-9a90-6c36f819410e}
"Tiny Linux" {44ed7a1d-4e75-4d21-9bdd-a23699603af4}
"Turnkey Linux" {a2194ccb-c88d-48b9-aa6f-12b0805500c9}

So, to boot the Turnkey Linux box, just enter..

VBoxManage startvm "Turnkey Linux" --type headless

You should get

VBoxManage startvm "Turnkey Linux" --type headless
Waiting for VM "Turnkey Linux" to power on...
VM "Turnkey Linux" has been successfully started.

Now, just ssh straight onto the machine

ssh root@192.168.10.123

Obviously, you need to know the ip address of the machine in advance or see your DHCP log to see what address it picked up. Otherwise, you’re ready to log in.

To shut it down again…

VBoxManage controlvm "Turnkey Linux" poweroff

Sweet!

Check out the well-written and compact documentation for VirtualBox here.

posted under Linux Tips | No Comments »

Mount a CD in Linux

September18

This works for any version of Linux as it’s a universal command and is very simple.

First, su as root

$sudo su

Now create the directory where you want to see the CD/DVD files..

# mkdir -p /media/mycd

Now use the mount command to mount the CD

# mount -o loop /path/to/my/iso/my_favourite.iso /media/mycd

The files are now visible in /media/mycd.

Done.

posted under Linux Tips | No Comments »
« Older Entries