说明:蓝色=命令名称
浅绿=命令参数
浅蓝=选项
紫色=目录
一、安装简介
用户名:mysql
安装目录:/usr/local/mysql-5.5.20
数据库目录:/data/mysql/data
源码包:mysql-5.5.21.tar.gz
二、安装准备
添加用户
useradd
建立所需目录
mkdir
chown
安装编译所需文件或程序
yum
下载源码包
wget
三、编译安装
cd
tar
cd
CFLAGS="-O3"
CXXFLAGS="-O3
cmake
-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
chown
mv
注:在/usr/local/src/mysql-5.5.21/support-files/文件夹中有多个my-****.cnf
[root@localhost
#
#
#
#
mv
chmod
chkconfig
/usr/local/mysql-5.5.21/scripts/mysql_install_db
--defaults-file=/etc/my.cnf
--basedir=/usr/local/mysql-5.5.21/
--datadir=/data/mysql/data/
echo
source
补充:
从mysql5.5起,mysql源码安装开始使用cmake。下面是
configure | CMake |
./configure | cmake |
./configure | cmake |
Parameter | configure | CMake | CMake | ||||||||
Installation | --prefix=/usr | -DCMAKE_INSTALL_PREFIX=/usr | | ||||||||
mysqld | --libexecdir=/usr/sbin | -DINSTALL_SBINDIR=sbin | interpreted | ||||||||
Data | --localstatedir=/var/lib/mysql | -DMYSQL_DATADIR=/var/lib/mysql | | ||||||||
Config | --sysconfdir=/etc/mysql | -DSYSCONFDIR=/etc/mysql | | ||||||||
Plugin | --with-plugindir=/usr/lib64/mysql/plugin | -DINSTALL_PLUGINDIR=lib64/mysql/plugin | interpreted | ||||||||
Man | --mandir=/usr/share/man | -DINSTALL_MANDIR=share/man | interpreted | ||||||||
Shared-data | --sharedstatedir=/usr/share/mysql | -DINSTALL_SHAREDIR=share | this | ||||||||
Library | --libdir=/usr/lib64/mysql | -DINSTALL_LIBDIR=lib64/mysql | interpreted | ||||||||
Header | --includedir=/usr/include/mysql | -DINSTALL_INCLUDEDIR=include/mysql | interpreted | ||||||||
Info | --infodir=/usr/share/info | -DINSTALL_INFODIR=share/info | interpreted | ||||||||
Parameter | configure | CMake | CMake | ||||||||
readline | --with-readline | -DWITH_READLINE=1 | | ||||||||
SSL | --with-ssl=/usr | -DWITH_SSL=system | | ||||||||
zlib | --with-zlib-dir=/usr | -DWITH_ZLIB=system | | ||||||||
libwrap | --without-libwrap | -DWITH_LIBWRAP=0 | | ||||||||
Parameter | configure | CMake | CMake | ||||||||
TCP/IP | --with-tcp-port-=3306 | -DMYSQL_TCP_PORT=3306 | | ||||||||
UNIX | --with-unix-socket-path=/tmp/mysqld.sock | -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock | | ||||||||
Enable | --enable-local-infile | -DENABLED_LOCAL_INFILE=1 | | ||||||||
Extra | --with-extra-charsets=all | -DEXTRA_CHARSETS=all | default | ||||||||
Default | --with-charset=utf8 | -DDEFAULT_CHARSET=utf8 | | ||||||||
Default | --with-collation=utf8_general_ci | -DDEFAULT_COLLATION=utf8_general_ci | | ||||||||
Build | --with-server | none | | ||||||||
Build | --with-embedded-server | -DWITH_EMBEDDED_SERVER=1 | | ||||||||
libmysqld | --with-embedded-privilege-control | none | always | ||||||||
Install | --without-docs | none | | ||||||||
Big | --with-big-tables, | none | tables | ||||||||
mysqld | --with-mysqld-user=mysql | -DMYSQL_USER=mysql | mysql | ||||||||
Debugging | --without-debug | -DWITH_DEBUG=0 | default | ||||||||
GIS | --with-geometry | none | always | ||||||||
Community | --enable-community-features | none | always | ||||||||
Profiling | --disable-profiling | -DENABLE_PROFILING=0 | enabled | ||||||||
pstack | --without-pstack | none | pstack | ||||||||
Assembler | --enable-assembler | none | | ||||||||
Build | --build=x86_64-pc-linux-gnu | no | unneeded? | ||||||||
Cross-compile | --host=x86_64-pc-linux-gnu | no | unneeded? | ||||||||
Client | --with-client-ldflags=-lstdc++ | none | unneeded | ||||||||
Client | --enable-thread-safe-client | none | unneeded, | ||||||||
Comment | --with-comment='string' | -DWITH_COMMENT='string' | | ||||||||
Shared/static | --enable-shared | none | there | ||||||||
Memory | --with-low-memory | none | unneeded |
1.
重新编译时,需要清除旧的对象文件和缓存信息
2.安装选项
CMAKE_INSTALL_PREFIX值是安装的基本目录,其他cmake选项值是不包括前缀,是相对路径名,绝对路径包括CMAKE_INSTALL_PREFIX路径。如-DINSTALL_SBINDIR=sbin的绝对路径是/usr/local/mysql/sbin
mysql存储引擎是插件式的,因此插件控制选项可以指定那个存储引擎安装。
configure编译插件选项--with-plugins=csv,myisam,myisammrg,heap,innobase,
archive,blackhole在cmake中没有直接对应的相同选项。对于csv,myisam,myisammrg,heap在cmake中是不需要明确指定存储引擎的名称,因为它们是强制性安装。
可以使用以下选择来安装innodb,archive,blackhole存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
(1可以使用on代替)
4.其他选项
--with-embedded-server
5.调试配置过程
编译参数参考:
BUILD_CONFIG
CMAKE_BUILD_TYPE
CMAKE_INSTALL_PREFIX
CPACK_MONOLITHIC_INSTALL是否建立单个安装包文件
DEFAULT_CHARSET
DEFAULT_COLLATION
ENABLE_DEBUG_SYNC
ENABLE_DOWNLOADS
ENABLE_DTRACE
ENABLE_GCOV
ENABLED_LOCAL_INFILE
ENABLED_PROFILING
INSTALL_BINDIR
INSTALL_DOCDIR
INSTALL_DOCREADMEDIR
INSTALL_INCLUDEDIR
INSTALL_INFODIR
INSTALL_LAYOUT
INSTALL_LIBDIR
INSTALL_MANDIR
INSTALL_MYSQLSHAREDIR
INSTALL_MYSQLTESTDIR
INSTALL_PLUGINDIR
INSTALL_SBINDIR
INSTALL_SCRIPTDIR
INSTALL_SHAREDIR
INSTALL_SQLBENCHDIR
INSTALL_SUPPORTFILESDIR
MYSQL_DATADIR
MYSQL_MAINTAINER_MODE
MYSQL_TCP_PORT
MYSQL_UNIX_ADDR
SYSCONFDIR
WITH_COMMENT
WITH_DEBUG
WITH_EMBEDDED_SERVER
WITH_xxx_STORAGE_ENGINE
WITH_EXTRA_CHARSETS
WITH_LIBWRAP
WITH_READLINE
WITH_SSL
WITH_ZLIB
WITHOUT_xxx_