2015-06-24

MySql in ubuntu, and replication.


mysql install in Ubuntu:


  1. sudo apt-get update
  2. sudo apt-get install mysql-server
    1. modify for my.cnf (in /etc/mysql) :
      1. bind-address  = 10.1.1.1
    2. allow remote hosts to use root to login:
    1. mysql -u root -p
    1. mysql>use mysql;
    1. mysql>update user set host = '%' where user = 'root';
    1. mysql>flush privileges;
  3. replications:
    1. source db:
      • in my.cnf:
        • log-bin=C:/Program Files/MySQL/MySQL Server 5.0/log/replication.log
        • server-id=1
        • restart mysql
      • mysql --user=user --password=password
        • FLUSH TABLES WITH READ LOCK;
        • SHOW MASTER STATUS;
        • keep File, Position
      • mysqldump --user=user --password=password --all-databases --master-data | gzip > dbdump.db.gz
        • 備份部份 DB: mysqldump --databases db1 db2
      • after mysqldump, 
        • mysql>UNLOCK TABLES;
    2. slave db:
      • gunzip < dbdump.db.gz | mysql -p
        • or mysql --user=user --password=password < dbdump.db
      • mysql>STOP SLAVE;
        
        mysql>CHANGE MASTER TO 
        MASTER_HOST='host name',
        MASTER_PORT=3306,
        MASTER_USER='username',
        MASTER_PASSWORD='password',
        MASTER_LOG_FILE='logfile',
        MASTER_LOG_POS=recorded_log_position;
        
        mysql>START SLAVE;
      •  show slave status
    3. in Ubuntu, mysql table name 預設是區分大小寫:
      1. (in my.cnf) lower_case_table_names=1   不區分大小寫

others:
  1. ubuntu 時間設定:
    1. 如果有 ntp service: service ntp stop
    2. ntpdate xx.xx.xx.xx   (time server)

2015-06-07

First Python practice


  • 第一個 Python 練習
  • Environment:
    • windows 8
    • Python 3.4
    • IDE:
      • Visual Studio 2013 + Python Tool for Visual Studio (PTVS)
      • PyScripter
      • test other IDE:
        • Sublime Text
        • PyCharm: seems to need more resources to run it, like busy CPU.
  • Target:
    1. 跟 python 親近一點
    2. write function in another file
    3. read/write file (IO) with utf-8 encoding
    4. access MariaDB/MySQL database
    5. use GitHub: workingrichard/PythonFirst

2014-08-27

win8 + ubuntu 14 雙系統




environment: windows 8.1 + ubuntu 14.04 LTS 雙系統


  • 安裝:
    • 安裝好 windows 8 後,接著安裝 ubuntu。
      • 由於在 windows 中,C, D 都設成了 primary disk。
      • 壓縮 C 切出一個空的 partition。
      • 以致於 ubuntu 再切時,/ 可以設成 primary disk,但不能再新增 swap。很有可能是因為已經有了4個 primary disk 了。改將 / 設成 logic disk,就可以新增 swap 了。
      • 不過,很有可能因為上述,變成開機直接進入 windows 而沒有 boot menu 可以選擇進入 ubuntu。
    • 開機進入 windows 8 後,下載使用 EasyBCD 軟體:
      • Add New Entry: Linux/BSD, type: Grub 2, partition 選擇安裝的 ubuntu partition。儲存套用,重開機後,boot menu 就出現可以選擇 windows 或是 自定的名稱了。
    • 故障排除:
      • 安裝時,如果出現 "The installer encountered an unrecoverable error. A desktop session will now be run so that you may investigate the problem or try installing again." 這樣子的錯誤訊息,在一開始就無法安裝了。
        檢查了 iso MD5,試了 ubuntu 14.01 光碟、14.10 USB 開機安裝,都是這樣的錯誤訊息。網路上也有人認為關閉安裝的介紹(slide show)可以解決,但我都不行。(不過,linux Mint 是可以的)
        解法:不要啟動無線網路,也不要安裝時更新,直接就光碟內容安裝即可進行下去。

  • 中文:
    • 字型:
    • ibus 中文輸入法的設定畫面:
      • > ibus-setup
      • ref: http://www.pinyinjoe.com/linux/ubuntu-12-chinese-setup.htm
        http://www.pinyinjoe.com/linux/ubuntu-10-chinese-input-pinyin-chewing.htm
      • http://wiki.linux.org.hk/w/Configure_IBus
    • 安裝 gnome classic version 後,language support icon 不見了:
      • sudo apt-get install language-selector-gnome
      • 改選 gcin 輸入法
      • 倉頡:可使用五四三倉頡。

2013-09-30

在 windows 裡架起 Cassandra

install Cassandra in windows system

在 windows 系統上,加起 cassandra,實作起來不難,簡單步驟為:
(1) 安裝 java (JRI)
(2) 下載 cassandra tar, 並解開。
(3) 設定新增兩個系統環境變數: JAVA_HOME , CASSANDRA_HOME
(4) 修改 cassandra 設定檔 cassandra.yaml , 設好 cassandra 目錄所在。
(5) 啟動 cassanda,完成。


2013-08-28

How to union multiple table in MySQL?

database: MySQL

如果有多個 table 要合併起來,如果有 foreign key 要對應,一般都是用上 join 的語法。
但是,table 之間沒有關係,純綷只是要將各 table 中的所有 record 集合起來,那麼,就可以用上 union 的語法了:

select agentid as id, agentname as name  from agent
union
select cid, name from category
union
select id, adid from admanagement;

result:
id name
--------------
1 agent1
2 agent2
1 ca1
2 ca2
1 ad1
2 ad2

也可以加上一個欄位(文字或數值),直接來區分屬於那個 table 的內容:


select agentid as id, agentname as name, "agent" as type from agent
union
select cid, name, "category" from category
union
select id, adid, "ad" from admanagement;

result:

id name type
-----------------------
1 agent1 agent
2 agent2 agent
1 ca1 category
2 ca2 category
1 ad1 ad
2 ad2 ad

後記: 當資料量大時,效能不知如何...



後來,再查時,發現使用 union all 的速度會快過使用 union,原因在於 union all 不會去除重複,而 union 語法時,MySQL 會試著去過濾重複的資料。因此,如果確定 table 之間不會有重複的資料,可以直接下 union all 試看看:

select agentid as id, agentname as name, "agent" as type from agent
union all
select cid, name, "category" from category
union all
select id, adid, "ad" from admanagement;


2013-02-01

root TF101, and upgrade to EOS 4 JELLYBEAN (4.2)

自從 TF101 由 Android 3.x 升級到官方所釋出的 Android 4.0 之後,使用經驗是大打折扣。原因有二:

(1) 首先,桌面圖示有時會憑空消失了。再怎麼試也無法出現,除非重新開始。
而這會有什麼影響呢? 除了最近開啟過的 app 之外,只剩下"設定"的功能可以用而已,無法再啟動其他的 app 了。
後來,安裝了 Apex launcher,再改用 Nova launcher,情況改善了,但是還是偶爾會發生桌面 app icon 全部消失的狀況。

(2) 另外,前一陣蠻著迷 2013 棒球的遊戲。結果,遊戲一啟動或是進行到一半,會突然出現一半亂彩色的畫面,接著畫面就沒有反應了。必須 kill 遊戲再重啟,但還是會再發生。常常必須得重新開機才行。

眼看著原廠似乎沒有支援 TF101 這第一代平板的 OS 升級打算,於是就想到: 既然過了保固了,那就來 root & 升級 OS 吧!!


2012-11-30

compare performance in Dictionary and ConcurrentDictionary

Dictionary 類別,是不支援 thread safe 的。
意思是說,在 multi-thread 環境下,如果同時直接 read/write dictionary 、而不 lock (或沒有使用 InterChange) 的話,就有可能發生 exception。

在 .net 4.0 之後,針對平行處理提供了許多類別,其中之一就是 ConcurrentDictionary (so also)。
也就是在 multi-thread 環境,就算有同時 read/write 的可能,也不用自己實做 lock 機制,系統支援了。

這當然是一個好消息。

但是,第一個首要擔心的是: 效能會不會掉。

這裡,先就 single thread 來簡單測試一下: