ryu's blog just a few lines of code

19Apr/110

MySQL: Convert BLOB inside Query

Example: s.data is a BLOB field.

SELECT CAST(s.data AS CHAR(10000) CHARACTER SET utf8) as blabla FROM sync_transport s LIMIT 0,1000

or

SELECT CONVERT(s.data USING utf8) as blabla FROM sync_transport s LIMIT 0,1000

Tagged as: , No Comments
15Apr/110

The difference between utf8_general_ci, utf8_unicode_ci & utf8_bin

I found this very interesting question at stackoverflow:

What are the diffrences between utf8_general_ci and utf8_unicode_ci?

utf8_general_ci is a very simple collation. What it does - it just - removes all accents - then converts to upper case

utf8_unicode_ci supports so called expansions and ligatures, for example: German letter ß (U+00DF LETTER SHARP S) is sorted near "ss" Letter Œ (U+0152 LATIN CAPITAL LIGATURE OE) is sorted near "OE".
utf8_general_ci does not support expansions/ligatures, it sorts all these letters as single characters, and sometimes in a wrong order.

utf8_unicode_ci is generally more accurate for all scripts. For example, on Cyrillic block: utf8_unicode_ci is fine for all these languages: Russian, Bulgarian, Belarusian, Macedonian, Serbian, and Ukrainian. While utf8_general_ci is fine only for Russian and Bulgarian subset of Cyrillic. Extra letters used in Belarusian, Macedonian, Serbian, and Ukrainian are sorted not well.
The disadvantage of utf8_unicode_ci is that it is a little bit slower than utf8_general_ci.

So when you need better sorting order - use utf8_unicode_ci, and when you utterly interested in performance - use utf8_general_ci.

Source: http://forums.mysql.com/read.php?103,187048,188748#msg-188748

Source: http://stackoverflow.com/questions/1036454/what-are-the-diffrences-between-utf8-general-ci-and-utf8-unicode-ci

Additional I can say: utf8_bin is case-sensitive because it's binary! :)

Tagged as: , No Comments
8Feb/100

MySQL Dump Backup-Rotation

#!/bin/bash

TIME1=$(date +%d_%m_%Y__%H_%M_%S)
user="root"
passwd="xxxxxx"

# blabla db
db="blabla"
mysqldump -c -f -Q --user=${user} --password=${passwd} --host=localhost ${db} | gzip -f > /root/backup/db_${db}.$TIME1.sql.gz
find /root/backup/db_${db}.*.sql.gz -mtime +3 -exec rm {} ;

Tagged as: , , No Comments