Linux下原始碼編譯方式安裝MySQL5.5

junsansi發表於2011-05-18

  Msyql升級到5.5版本之後,原始碼編譯配置工具換成了CMake,編譯方式及載入的引數較之以前都有不小的變化,本節以實戰形式詳盡描述RHEL5環境下,原始碼編譯安裝MySQL5.5的各個步驟。 

  工欲善其事,必先利其器。如果作業系統沒有cmake命令,則需要首先編譯安裝cmake,這個工具安裝比較簡單,可以先到下列網址下載:http://www.cmake.org/cmake/resources/software.html,解壓縮後make安裝即可。

  MySQL的原始碼包可以到其官網下載:http://dev.mysql.com/downloads/mysql/5.5.html,目前最新版本為5.5.12GA。

  安裝的詳細操作步驟請看官們注意了,往下瞅~~

  首先建立專用帳戶:

    shell> groupadd mysql

    shell> useradd -r -g mysql mysql

  解壓縮MySQL安裝包:

    [root@rhel5u3 software]# tar xvfz mysql-5.5.12.tar.gz

    [root@rhel5u3 software]# cd mysql-5.5.12

  接下來需要執行cmake命令進行配置。有過原始碼編譯安裝MySQL經驗的朋友都知道,5.5之前版本編譯時的引數眾多,某些引數對效能也有相當影響,比如靜態編譯的選項等等。

  MySQL5.5版本中,編譯的選項同樣眾多,DBA可以通過# cmake . -LH 檢視支援的引數,或者瀏覽下列頁面:http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html,檢視編譯時可指定引數的詳細描述。

  截略一些常用引數如下:

  • CMAKE_INSTALL_PREFIX:指定MySQL程式的安裝目錄,預設/usr/local/mysql
  • DEFAULT_CHARSET:指定伺服器預設字符集,預設latin1
  • DEFAULT_COLLATION:指定伺服器預設的校對規則,預設latin1_general_ci
  • ENABLED_LOCAL_INFILE:指定是否允許本地執行LOAD DATA INFILE,預設OFF
  • WITH_COMMENT:指定編譯備註資訊
  • WITH_xxx_STORAGE_ENGINE:指定靜態編譯到mysql的儲存引擎,MyISAM,MERGE,MEMBER以及CSV四種引擎預設即被編譯至伺服器,不需要特別指定。
  • WITHOUT_xxx_STORAGE_ENGINE:指定不編譯的儲存引擎
  • SYSCONFDIR:初始化引數檔案目錄
  • MYSQL_DATADIR:資料檔案目錄
  • MYSQL_TCP_PORT:服務埠號,預設3306
  • MYSQL_UNIX_ADDR:socket檔案路徑,預設/tmp/mysql.sock

  實際執行時指定的引數如下:

    [root@rhel5u3 mysql-5.5.12]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql55 \

    >  -DDEFAULT_CHARSET=gbk \

    >  -DDEFAULT_COLLATION=gbk_chinese_ci \

    >  -DENABLED_LOCAL_INFILE=ON \

    >  -DWITH_INNOBASE_STORAGE_ENGINE=1 \

    >  -DWITH_FEDERATED_STORAGE_ENGINE=1 \

    >  -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

    >  -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \

    >  -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \

    >  -DWITH_COMMENT="jss edition" \

    >  -DMYSQL_UNIX_ADDR=/data/mysqldata/3306/mysql.sock \

    >  -DSYSCONFDIR=/data/mysqldata/3306

    ...........

    ...........

    -- The C compiler identification is GNU

    -- The CXX compiler identification is GNU

    -- Check for working C compiler: /usr/bin/gcc

    -- Check for working C compiler: /usr/bin/gcc -- works

  而後執行make命令進行編譯操作:

    [root@rhel5u3 mysql-5.5.12]# make

    Scanning dependencies of target INFO_BIN

    [  0%] Built target INFO_BIN

    Scanning dependencies of target INFO_SRC

    ...........

    ...........

  執行make install命令安裝程式到指定的路徑:

    [root@rhel5u3 mysql-5.5.12]# make install

    [  0%] Built target INFO_BIN

    [  0%] Built target INFO_SRC

    [  0%] Built target abi_check

    ...........

    ...........

  如果前面操作沒有碰到錯誤的話,編譯及安裝至此告以段落,接下來要對MySQL做些配置性工作,比如授予目錄許可權,建立資料等等。

  首先修改安裝目錄的所有者,執行命令如下:

    [root@rhel5u3 mysql-5.5.12]# cd /usr/local/mysql55

    [root@rhel5u3 mysql55]# chown -R mysql:mysql ./

  為將要建立的資料庫做準備性工作,建立相關目錄,並修改所有者:

    [root@rhel5u3 mysql55]# cd /data/mysqldata/3306

    [root@rhel5u3 3306]# mkdir data binlog tmp innodb_ts innodb_log

    [root@rhel5u3 3306]# chown -R mysql:mysql ./

    [root@rhel5u3 3306]# cd /usr/local/mysql55

  執行mysql_install_db命令建立資料庫:

    [root@rhel5u3 mysql55]# scripts/mysql_install_db --user=mysql --datadir=/data/mysqldata/3306/data/

    Installing MySQL system tables...

    OK

    Filling help tables...

    OK

    To start mysqld at boot time you have to copy

    support-files/mysql.server to the right place for your system

    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

    To do so, start the server, then issue the following commands:

    ./bin/mysqladmin -u root password 'new-password'

    ./bin/mysqladmin -u root -h rhel5u3 password 'new-password'

    Alternatively you can run:

    ./bin/mysql_secure_installation

    which will also give you the option of removing the test

    databases and anonymous user created by default.  This is

    strongly recommended for production servers.

    See the manual for more instructions.

    You can start the MySQL daemon with:

    cd . ; ./bin/mysqld_safe &

    You can test the MySQL daemon with mysql-test-run.pl

    cd ./mysql-test ; perl mysql-test-run.pl

    Please report any problems with the ./bin/mysqlbug script!

複製初始化引數檔案到適當的路徑下,前面編譯配置時已經指定了初始化引數檔案預設路徑為/data/mysqldata/3306,因此這裡要將引數檔案複製至該路徑下,注意不要複製錯了地方:

    [root@rhel5u3 mysql55]# cp support-files/my-medium.cnf /data/mysqldata/3306/my.cnf

vi編譯my.cnf檔案,新增下列的配置:

    datadir  = /data/mysqldata/3306/data

    tmpdir   = /data/mysqldata/3306/tmp

如果有必要的話,將innodb相關的引數註釋去掉,並修改檔案路徑為正確的路徑,然後就可以啟動mysql了:

    [root@rhel5u3 mysql55]# /usr/local/mysql55/bin/mysqld_safe &

在啟動時不需要附加--defaults-file引數指定引數檔案的具體路徑了。

通過mysqladmin命令修改管理員口令:

    [root@rhel5u3 mysql55]# /usr/local/mysql55/bin/mysqladmin -uroot password '123456' -S /data/mysqldata/3306/mysql.sock

登入資料庫:

    [root@rhel5u3 mysql55]# /usr/local/mysql55/bin/mysql -uroot -p'123456'

    Welcome to the MySQL monitor.  Commands end with ; or \g.

    Your MySQL connection id is 2

    Server version: 5.5.12-log Source distribution

    Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

    Oracle is a registered trademark of Oracle Corporation and/or its

    affiliates. Other names may be trademarks of their respective

    owners.

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    mysql> show databases;

    +--------------------+

    | Database           |

    +--------------------+

    | information_schema |

    | mysql              |

    | performance_schema |

    | test               |

    +--------------------+

    4 rows in set (0.00 sec)

竣工!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7607759/viewspace-695654/,如需轉載,請註明出處,否則將追究法律責任。

相關文章