Monthly Archives: May 2013

Create temporary table in MySQL

Temporary tables are useful when you need to do something on the fly. Instead of writing full CREATE TABLE statement and then inserting from another table, you can do the following with one query:

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name

Source: http://linuxapachemysqlphp5.blogspot.com/2013/05/create-temporary-table-in-mysql.html

Create swap file in Linux

Before creating a swap file, we should check the size of the current swap:

#cat /proc/meminfo | grep SwapTotal
SwapTotal: 9233400 kB

Create a swap file
To create swap file, you will need to use dd command:

#dd if=/dev/zero of=/newswap bs=1024 count=1048576

if=/dev/zero – read from /dev/zero
of=/newswap – write to /newswap
bs=1024 – blocksize in bytes for reading and writing
count=1048576 – swap file size

Source: http://linuxapachemysqlphp5.blogspot.com/2013/05/create-swap-file-in-linux.html

Add, Edit, Delete, List cronjobs in Linux

If you want to add cronjob or edit an existing one you can use the crontab command:

#crontab -e

The ‘-e’ param stands for edit. This will open the crontab file for the current logged user. If you want to edit the crontab file for a specific user you need to specify the username:

#crontab -e -u username

Source: http://linuxapachemysqlphp5.blogspot.com/2013/05/add-edit-delete-list-cronjobs-in-linux.html

List all ip addresses on a linux system

With the ifconfig command you can list all network cards and ip addresses on a linux system.

#ifconfig

eth0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: 0000::000:0000:0000:000/00 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:54367 errors:0 dropped:0 overruns:0 frame:0
TX packets:34504 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:247741252 (247.7 MB) TX bytes:127569007 (127.5 MB)
Interrupt:28 Base address:0x0000

lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2394 errors:0 dropped:0 overruns:0 frame:0
TX packets:2394 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:178041 (173.6 KiB) TX bytes:178041 (173.6 KiB)

Source: http://linuxapachemysqlphp5.blogspot.com/2013/05/list-all-ip-addresses-on-linux-system.html

ERROR 1271 (HY000): Illegal mix of collations for operation…

The following MySql error occurs when you try to make operation on two fields with different collations. To check the field collation you can use the show create query:

mysql> show create table words;

CREATE TABLE `words` (
`word` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1

Source: http://linuxapachemysqlphp5.blogspot.com/2013/05/error-1271-hy000-illegal-mix-of.html