mysql 5.5.15 原始碼包在linux5.5_x86_64 安裝

wangxiangtao發表於2011-08-08

首先在mysql 的官方網站下載安裝所需要的原始碼包, 由於原始碼包的安裝需要cmake 的支援,因此:

[root@mysqla ~]# uname -a

Linux mysqla.richinfo.cn 2.6.18-194.el5xen #1 SMP Tue Mar 16 22:01:26 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

[root@mysqla ~]# cd /soft/

[root@mysqla soft]# ll

total 28652

-rw-r--r-- 1 root root  5517977 Aug  7 12:01 cmake-2.8.5.tar.gz

-rw-r--r-- 1 root root 23774015 Aug  7 12:02 mysql-5.5.15.tar.gz

(1) cmake 的安裝

[root@mysqla soft]# tar -xvf cmake-2.8.5.tar.gz

[root@mysqla cmake-2.8.5]# vim Readme.txt

從文件中獲取以下安裝步驟

$ ./bootstrap;

make;

make install

(2) mysql 的安裝

A. 建立 mysql 使用者 以及mysql

[root@mysqla cmake-2.8.5]# groupadd mysql

[root@mysqla cmake-2.8.5]# useradd -g mysql mysql

B. 建立mysql資料庫的相關目錄, 並且賦予許可權

[root@mysqla cmake-2.8.5]# mkdir  /usr/local/mysql

[root@mysqla cmake-2.8.5]# mkdir /data/mysql -p

[root@mysqla cmake-2.8.5]# mkdir /etc/mysql

 

[root@mysqla cmake-2.8.5]# chown mysql.mysql /usr/local/mysql

[root@mysqla cmake-2.8.5]# chown mysql.mysql /etc/mysql

[root@mysqla cmake-2.8.5]# chown mysql.mysql /data/mysql –R

[root@mysqla etc]# chmod 755 /data/mysql -R

[root@mysqla etc]# chmod 755 /etc/mysql

[root@mysqla etc]# chmod 755 /usr/local/mysql

C.編譯 並安裝 mysql

Cmake 採用以下引數

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/mysql/data/  \

-DSYSCONFDIR=/etc/mysql/ \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DMYSQL_UNIX_ADDR=/etc/mysql/mysqld.sock \

-DMYSQL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DMYSQL_USER=mysql

相關引數的 查詢可以參考幫助文件:

[root@mysqla mysql-5.5.15]# cmake . -LH

-- MySQL 5.5.15

-- Configuring done

-- Generating done

-- Build files have been written to: /soft/mysql-5.5.15

-- Cache values

也可以 檢視官檔:

http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html

 

  • -DSYSCONFDIR=dir_name

The default my.cnf option file directory.   // mysql my.cnf 存放路徑

  • DMYSQL_UNIX_ADDR=file_name

The Unix socket file path on which the server listens for socket connections. This must be an absolute path name. The default is /tmp/mysql.sock.

This value can be set at server startup with the --socket option.  //socket 的存放路徑, 其檔案用於伺服器的監聽和套接連結

################################################################

Cmake 時會出現如下警告資訊:

CMake Warning:

  Manually-specified variables were not used by the project:

 MYSQL_USER

去掉 -DMYSQL_USER=mysql 引數

[root@mysqla mysql-5.5.15]# rm  CMakeCache.txt

rm: remove regular file `CMakeCache.txt'? y

繼續編譯 透過 

#############################################################################

 

如果出現一下錯誤:

cmake .

-- MySQL 5.5.8

-- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)

CMake Error at cmake/readline.cmake:82 (MESSAGE):

  Curses library not found.  Please install appropriate package,

 

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.

Call Stack (most recent call first):

  cmake/readline.cmake:126 (FIND_CURSES)

  cmake/readline.cmake:216 (MYSQL_USE_BUNDLED_LIBEDIT)

  CMakeLists.txt:256 (MYSQL_CHECK_READLINE)

 

 

-- Configuring incomplete, errors occurred!

 

 

安裝:

# yum -y install ncurses-devel

##############################################################################

 

Make

Make install

 

複製配置檔案 my.cnf

[root@mysqla mysql]# cp /soft/mysql-5.5.15/support-files/my-medium.cnf /etc/mysql/my.cnf

使用chown chmod  更改 檔案的許可權與屬組

 

配置開機自啟動:

 

[root@mysqla mysql]# cp /soft/mysql-5.5.15/support-files/mysql.server /etc/init.d/mysql

[root@mysqla mysql]# chmod +x /etc/init.d/mysql

[root@mysqla mysql]# chkconfig  --add mysql

[root@mysqla mysql]# chkconfig mysql on

[root@mysqla mysql]# chkconfig --list | grep mysql

mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off

 

[root@mysqla mysql]# /usr/local/mysql/scripts/mysql_install_db  --basedir=/usr/local/mysql --datadir=/data/mysql/ --user=mysql

Installing MySQL system tables...

110807 16:25:41 [ERROR] Unknown collation: 'utf8-general_ci'

110807 16:25:41 [ERROR] Aborting

 

110807 16:25:41 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

由於在編譯時採用了 錯誤的 DDEFAULT_COLLATION=utf8-general_ci(utf8_general_ci) 設定, 因此在my.cnf 使用了 character_set_server = utf8 初始化DB

但是在登入時,也出現了一下錯誤:

[root@mysqla mysql]# /usr/local/mysql/bin/mysql -uroot -p

Enter password:

/usr/local/mysql/bin/mysql: Collation 'utf8-general_ci' is not a compiled collation and is not specified in the '/usr/local/mysql/share/charsets/Index.xml' file

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

[root@mysqla mysql]#  /usr/local/mysql/bin/mysqladmin -u root password '123456'

/usr/local/mysql/bin/mysqladmin: Collation 'utf8-general_ci' is not a compiled collation and is not specified in the '/usr/local/mysql/share/charsets/Index.xml' file

 

 

[root@mysqla mysql]# vim /usr/local/mysql/share/charsets/Index.xml

 

 

[root@mysqla mysql]#  /usr/local/mysql/bin/mysqladmin -u root password '123456'

/usr/local/mysql/bin/mysqladmin: connect to server at 'localhost' failed

error: 'Access denied for user 'root'@'localhost' (using password: NO)'

 

更改了/usr/local/mysql/share/charsets/Index.xml 的內容:

  Unicode

  UTF-8 Unicode

  utf-8

  "utf8_general_ci"     id="33">

   primary

   compiled

 

              id="83">

    binary

    compiled

 

更改為:

  Unicode

  UTF-8 Unicode

  utf-8

  "utf8-general_ci"     id="33">

   primary

   compiled

 

              id="83">

    binary

    compiled

 

檢視官方文件:

 

  • -DDEFAULT_COLLATION=collation_name

The server collation. By default, MySQL uses latin1_swedish_ci. Use the SHOW COLLATION statement to determine which collations are available for each character set.

This value can be set at server startup with the --collation_server option.

個人理解: 每個字符集都有自己的預設 校驗字符集,  對於每種字符集的資料庫, mysql 均會採用指定的collation 方式, 排序就會用到此校驗規則。

mysql> create table tt (name varchar(10)) character set utf8;

Query OK, 0 rows affected (0.02 sec)

 

mysql> insert into tt values('aa');

Query OK, 1 row affected (0.01 sec)

 

mysql> insert into tt values('AA');

Query OK, 1 row affected (0.00 sec)

 

mysql> insert into tt values('ab');

Query OK, 1 row affected (0.01 sec)

 

mysql> insert into tt values('AB');

Query OK, 1 row affected (0.01 sec)

 

mysql> insert into tt values('ac');

Query OK, 1 row affected (0.00 sec)

 

mysql> insert into tt values('AC');

Query OK, 1 row affected (0.01 sec)

 

mysql> select * from tt order by name collate utf8_bin;

+------+

| name |

+------+

| AA   |

| AB   |

| AC   |

| aa   |

| ab   |

| ac   |

+------+

6 rows in set (0.01 sec)

 

mysql> select * from tt order by name collate utf8_general_ci;

+------+

| name |

+------+

| aa   |

| AA   |

| ab   |

| AB   |

| ac   |

| AC   |

+------+

6 rows in set (0.00 sec)

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

相關文章