2014年12月20日 星期六

[MariaDB]變更MariaDB的預設儲存引擎InnerDB到TokudB Part 2


為什縻要將預設引擎innerDB改為tokuDB請參考兩者之間的比較(光新增資料效率就差了100倍/秒)

http://www.tokutek.com/tokudb-for-mysql/tokudb-vs-innodb/



查詢mysql版本:mysql --version

10.x.x-MaridB代表新安裝的



5.x.x - MariaDB 代表之前有裝過mysql







執行:dpkg-query -l libevent-*











確定有 libevent-1.4版,沒有的話執行(Ubuntu14預設是裝2.0版,要加裝1.4版不然執行TokuDB時會有錯誤)

先切換身份到root : sudo su ,接著執行

apt-get install libevent-1.4


下載tokuDB(下面網址選mariadb那一個)

http://www.tokutek.com/tokudb-for-mysql/download-community/












將檔案儲存在暫存的資料庫,我安裝在/temp中,沒有的話,執行:mkdir /temp

接著參考此篇安裝步驟:http://docs.tokutek.com/tokudb/tokudb-index-installation.html

1.建立mysql 群組指定為927(如果/etc/group己經有此群組請跳過)

groupadd -g 927 mysql

2.建立mysql 帳號並加入至927的mysql群組中(如果/etc/passwd中己經有此帳號請跳過)

useradd -r -u 927 -g mysql mysql

3.接著建立tokuDB要使用的資料夾

mkdir -pv /opt/tokutek

4.進到該資料夾中將剛剛下載的tokuDB的壓縮檔解壓縮

cd /opt/tokutek

tar xvzf /temp/[你下載的tokuDB壓縮檔名稱]

例.tar xvzf /temp/mariadb-5.5.40-tokudb-7.5.3-linux-x86_64.tar.gz

5.將解開後很長的檔案資料名稱連結到mysql這個名稱

ln -sv [你下載的tokuDB壓縮檔名稱] mysql

例.ln -sv mariadb-5.5.40-tokudb-7.5.3-linux-x86_64 mysql

6.將解壓縮後的資料夾變更擁有者和群組權限

chown -Rv mysql:mysql [你下載的tokuDB壓縮檔名稱]

例.chown -Rv mysql:mysql   mariadb-5.5.40-tokudb-7.5.3-linux-x86_64














7.將support-files資料夾中tokuDB提供的設定檔my-small.cnf蓋掉mysql中的my.cnf檔案(原文中的/etc/my.cnf是錯的,應該是/etc/mysql/my.cnf),記得先備份原有檔案my.cnf為my.cnf.bak

cp /etc/mysql/my.cnf /etc/mysql/my.cnf.bak

cp -v support-files/my-small.cnf /etc/mysql/my.cnf

8.接著在/etc/mysql/my.cnf中[mysqld]區段後增加以下內容

datadir = /var/lib/mysql
basedir = /opt/tokutek/mysql
user = mysql
log_error = /var/log/mysql/error.log

以及將原有的socket參數改回原本mysql的路徑

/var/run/mysqld/mysqld.sock
























9.重新初始化原有的系統資料表(目前路徑還在/opt/tokutek/mysql喲)

scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysql --basedir=/opt/tokutek/mysql

10.將原本/etc/init.d/mysql改成連結到tokuDB的mysql.server(一樣記得將原有的mysql備份起來)

mv /etc/init.d/mysql /etc/init.d/mysql.bak

ln -sv /opt/tokutek/mysql/support-files/mysql.server /etc/init.d/mysql

11.接著還要將hugepage關掉,不然/var/log/mysql/error.log中還會看到這個錯誤

請參考:[第三章]使用TokuDB前先將Huge pages 參數關掉

















12.最後啟動mysql 並確認TokuDB是否正常

/etc/init.d/mysql restart

mysql -u [mysql的管理員帳號] -p

例. mysql -u root -p

接著輸入 show plugins會看到tokuDB都是運作中

show plugins;

















再來show engines,會看到預設是tokuDB

show engines;









大功告成


==============測試=================

試著建立一個新表看看引擎是否預設為TokuDB

create database testdb ;

create table users
(
    id int not null,
    email char(50) not null,
    name char(20) not null
);


接著看users的資料表引擎

show table status from [DatabaseName] where name='[TableName]'

例. show table status from testdb where name='users'




OK !沒問題顯示為TokudB Engine



試著修改表格的engine

alter table [TableName] engine ='[Engine Name]'

例. alter table testdb.user engine ='Aria';











要將預設引擎變更可以執行

set default_storage_engine=[EngineName]






















沒有留言:

張貼留言

熱門文章