2015年1月25日 星期日

Instal Python Eggs

easy_install somepackage.egg

easy_install http://somehost.somedomain.com/somepackage.egg




References :
A small introduction to Python Eggs

2015年1月23日 星期五

MySQL show all grouped results

select t.Letter, t.Value
from MyTable t
inner join (
    select Letter, sum(Value) as ValueSum
    from MyTable
    group by Letter
) ts on t.Letter = ts.Letter
order by ts.ValueSum desc, t.Letter, t.Value desc




References :
sorting - MySQL show all grouped results and sort - Stack Overflow

Python read file don't include '\n'

with open(fname) as f:
    content = f.read().splitlines()




References :
string - Python: read file line by line into array - Stack Overflow

MySQL Error 1153 - Got a packet bigger than 'max_allowed_packet' bytes


因 MySQL 有單筆 SQL Query 長度的限制,在匯入檔案時,一次 INSERT 資料很大會錯誤,需調整單筆 SQL Query 長度

查詢目前 max_allowed_packet 設定值
mysql> show variables like 'max_allowed_packet';

更改爲 256MB (Client 需重新連結才會生效)

mysql> set global max_allowed_packet = 1024 * 1024 * 256;




References :
MySQL Error 1153 - Got a packet bigger than 'max_allowed_packet' bytes - Stack Overflow

2015年1月22日 星期四

MySQL 開啓檔案數


系統允許最大開啓檔案數
$ sysctl -a | grep fs.file-max
fs.file-max = 146925
$ cat /proc/sys/fs/file-max
146925
目前系統所有程式已開啓的檔案數
$ lsof | wc -l
18120
每個 shell 允許開啓檔案數
$ ulimit -n
1024
MySQL 最大允許開啓檔案數 (與 open_files_limit 變數設定 (default: 0) 或 ulimit 有關)
mysql> show variables like 'open_files_limit';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| open_files_limit | 1024 |
+------------------+-------+
MySQL 開啓的檔案數
$ pgrep mysqld
1661
1988
$ ls /proc/1988/fdinfo/ | wc -l
248
$ lsof -a -d 1-999 -p 1988
MySQL 目前開啓的檔案數
mysql> show status like '%Open_files%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Open_files | 221 |
+---------------+-------+