Tag Archives: convert

Migrate from mysql to percona

1
2
gpg --keyserver hkp://keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
gpg -a --export CD2EFD2A | sudo apt-key add -

add to /etc/apt/sources.list.d/percona.list

1
2
deb http://repo.percona.com/apt VERSION main
deb-src http://repo.percona.com/apt VERSION main

where VERSION is a name of your ubuntu version,
you can get it by command

1
lsb_release -a |grep name |awk '{print $2}'

backup data

1
2
cp -Rf /var/lib/mysql /var/lib/mysql-old
cp /etc/my.cnf /etc/my.cnf-old

Install percona (it automatically removes mysql and converts databases)

1
2
apt-get update
apt-get install percona-server-server-5.5 percona-server-client-5.5

Part of this article was taken from http://planet.jboss.org/post/drop_in_migration_from_mysql_to_percona_db_in_two_minutes

ext2 -> ext4 on SSD

umount /ssd # (if you have root «/» partition on ssd you should use livecd).
tune2fs -O extents,uninit_bg,dir_index,has_journal /dev/sdXN
# where /dev/sdXN is partition on the ssd
e2fsck -pf /dev/sda1 # you have to make check disk after converting fs
edit /etc/fstab
# discard options instead of default for enabling TRIM !
/dev/sdXN /ssd ext4 discard 1 2

mount -a

Python: convert to bits and to bytes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def tobits(s):
    result = []
    for c in s:
        bits = bin(ord(c))[2:]
        bits = '00000000'[len(bits):] + bits
        result.extend([int(b) for b in bits])
    return result


def frombits(bits):
    chars = []
    for b in range(len(bits) / 8):
        byte = bits[b*8:(b+1)*8]
        chars.append(chr(int(''.join([str(bit) for bit in byte]), 2)))
    return ''.join(chars)