說明:藍色=命令名稱
淺綠=命令參數
淺藍=選項
紫色=目錄
系統內容:CentOS 5.7 x86_64
一、安裝簡介
使用者名稱:mysql
安裝目錄:/usr/local/mysql-5.5.20
資料庫目錄:/data/mysql/data
源碼包:mysql-5.5.21.tar.gz
自動部署指令碼可在 下載
二、安裝準備
添加使用者
useradd -s /sbin/nologin mysql
建立所需目錄
mkdir -p /data/mysql/data
chown -R mysql:mysql /data/mysql
安裝編譯所需檔案或程式
yum install gcc gcc-c++ cmake ncurses-devel bison
下載源碼包
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.21.tar.gz/from/http://mirror.services.wisc.edu/mysql/ -P /usr/local/src
三、編譯安裝
cd /usr/local/src
tar xvf mysql-5.5.21.tar.gz
cd mysql-5.5.21
CFLAGS="-O3" CXX=gcc
CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti"
cmake -DMYSQL_USER=mysql \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.21 \
-DMYSQL_DATADIR=/data/mysql/data \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
註:詳細參數見下文補充內容。
make -j 2 && make install
註:-j 用來指定CPU核心數,可加快編譯速度,不加也可以。
chown -R mysql:mysql /usr/local/mysql-5.5.21/
mv /usr/local/src/mysql-5.5.21/support-files/my-large.cnf /etc/my.cnf
注:在/usr/local/src/mysql-5.5.21/support-files/檔案夾中有多個my-****.cnf 設定檔,具體用那一個設定檔根據自己實際情況。可以通過查看設定檔的頭部資訊來瞭解配置問價適合的配置。例如
[root@localhost support-files]# head /usr/local/src/mysql-5.5.21/support-files/my-huge.cnf
# Example MySQL config file for very large systems.
#
# This is for a large system with memory of 1G-2G where the system runs mainly
# MySQL.
mv /usr/local/src/mysql-5.5.21/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --level 345 mysqld on
/usr/local/mysql-5.5.21/scripts/mysql_install_db --user=mysql \
--defaults-file=/etc/my.cnf \
--basedir=/usr/local/mysql-5.5.21/ \
--datadir=/data/mysql/data/
echo "export PATH=/usr/local/mysql-5.5.21/bin:$PATH" >>/etc/profile
source /etc/profile
補充:
從mysql5.5起,mysql源碼安裝開始使用cmake。下面是 mysql 5.5 與以前的參數對照:
| configure Command |
CMake Command |
| ./configure |
cmake . |
| ./configure --help |
cmake . -LH or ccmake . |
| Parameter |
configure Option |
CMake Option |
CMake Notes |
| Installation base directory |
--prefix=/usr |
-DCMAKE_INSTALL_PREFIX=/usr |
|
| mysqld directory |
--libexecdir=/usr/sbin |
-DINSTALL_SBINDIR=sbin |
interpreted relative to prefix |
| Data directory |
--localstatedir=/var/lib/mysql |
-DMYSQL_DATADIR=/var/lib/mysql |
|
| Config directory (for my.cnf) |
--sysconfdir=/etc/mysql |
-DSYSCONFDIR=/etc/mysql |
|
| Plugin directory |
--with-plugindir=/usr/lib64/mysql/plugin |
-DINSTALL_PLUGINDIR=lib64/mysql/plugin |
interpreted relative to prefix |
| Man page directory |
--mandir=/usr/share/man |
-DINSTALL_MANDIR=share/man |
interpreted relative to prefix |
| Shared-data directory |
--sharedstatedir=/usr/share/mysql |
-DINSTALL_SHAREDIR=share |
this is where aclocal/mysql.m4 should be installed |
| Library installation directory |
--libdir=/usr/lib64/mysql |
-DINSTALL_LIBDIR=lib64/mysql |
interpreted relative to prefix |
| Header installation directory |
--includedir=/usr/include/mysql |
-DINSTALL_INCLUDEDIR=include/mysql |
interpreted relative to prefix |
| Info doc directory |
--infodir=/usr/share/info |
-DINSTALL_INFODIR=share/info |
interpreted relative to prefix |
| Parameter |
configure Option |
CMake Option |
CMake Notes |
| readline library |
--with-readline |
-DWITH_READLINE=1 |
|
| SSL library |
--with-ssl=/usr |
-DWITH_SSL=system |
|
| zlib library |
--with-zlib-dir=/usr |
-DWITH_ZLIB=system |
|
| libwrap library |
--without-libwrap |
-DWITH_LIBWRAP=0 |
|
| Parameter |
configure Option |
CMake Option |
CMake Notes |
| TCP/IP port number |
--with-tcp-port-=3306 |
-DMYSQL_TCP_PORT=3306 |
|
| UNIX socket file |
--with-unix-socket-path=/tmp/mysqld.sock |
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock |
|
| Enable LOCAL for LOAD DATA |
--enable-local-infile |
-DENABLED_LOCAL_INFILE=1 |
|
| Extra charsets |
--with-extra-charsets=all |
-DEXTRA_CHARSETS=all |
default is "all" |
| Default charset |
--with-charset=utf8 |
-DDEFAULT_CHARSET=utf8 |
|
| Default collation |
--with-collation=utf8_general_ci |
-DDEFAULT_COLLATION=utf8_general_ci |
|
| Build the server |
--with-server |
none |
|
| Build the embedded server |
--with-embedded-server |
-DWITH_EMBEDDED_SERVER=1 |
|
| libmysqld privilege control |
--with-embedded-privilege-control |
none |
always enabled? |
| Install the documentation |
--without-docs |
none |
|
| Big tables |
--with-big-tables, --without-big-tables |
none |
tables are big by default |
| mysqld user |
--with-mysqld-user=mysql |
-DMYSQL_USER=mysql |
mysql is the default |
| Debugging |
--without-debug |
-DWITH_DEBUG=0 |
default is debugging disabled |
| GIS support |
--with-geometry |
none |
always enabled? |
| Community features |
--enable-community-features |
none |
always enabled |
| Profiling |
--disable-profiling |
-DENABLE_PROFILING=0 |
enabled by default |
| pstack |
--without-pstack |
none |
pstack is removed |
| Assembler string functions |
--enable-assembler |
none |
|
| Build type |
--build=x86_64-pc-linux-gnu |
no equivalent |
unneeded? |
| Cross-compile host |
--host=x86_64-pc-linux-gnu |
no equivalent |
unneeded? |
| Client flag |
--with-client-ldflags=-lstdc++ |
none |
unneeded |
| Client flag |
--enable-thread-safe-client |
none |
unneeded, clients are always thread safe |
| Comment |
--with-comment='string' |
-DWITH_COMMENT='string' |
|
| Shared/static binaries |
--enable-shared --enable-static |
none |
there is only DISABLE_SHARED |
| Memory use |
--with-low-memory |
none |
unneeded |