24 October 2013

Clone a MySQL Table

First, create the new table.
CREATE TABLE new_table LIKE original_table;
Then, copy over the data.
INSERT INTO new_table SELECT * FROM original_table;

09 October 2013

GRANT MySQL with Limited Power

Grant only SELECT, INSERT and UPDATE to user.
GRANT SELECT,INSERT,UPDATE ON database.cryptonite TO 'superman@locahost';

16 July 2013

CREATE and GRANT MySQL with Super Power

CREATE a new MySQL user...
CREATE USER 'superman'@'localhost' IDENTIFIED BY 'password';
... and GRANT it super power.
GRANT ALL PRIVILEGES ON * . * TO 'superman'@'localhost' WITH GRANT OPTION;

06 June 2013

Migrating Wordpress

When migrating Wordpress from one domain name to another, remember to change some values in table 'wp_options'...
UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
... and 'wp_posts'.
UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

15 April 2013

Copy MySQL DB

You need to have (remote) access to both source and target host/database.
mysqldump -h source_host -u source_user -psource_password source_db | mysql -h target_host -u target_user -ptarget_password target_db
Note: there is no space between -psource_password or -ptarget_password

Tarball

Compress /directory/to/compress into archived.tar.gz
tar -zcf archived.tar.gz /directory/to/compress
Uncompress archived.tar.gz
tar -zxf archived.tar.gz
Uncompress archived.tar.gz into /directory/to/uncompress. /directory/to/uncompress need to exist.
tar -zxf archived.tar.gz -C /directory/to/uncompress/

30 January 2013

Static IP on Linux

Setting static IP and resolv.conf to prevent resolv.conf being reset on reboot.

/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:24:1F:23:65:C1
NM_CONTROLLED=yes
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.3.183
NETMASK=255.255.255.0
GATEWAY=192.168.3.1

/etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

04 January 2013

Yii Debug

error_reporting(E_ALL);
ini_set('display_errors', '1');

Recursive Download using FTP

Recursively download files, while not creating any host directory, and skip downloads that would download to existing files.
wget -r -nH -c --ftp-user=USER --ftp-password=PASS ftp://domainname.com