一、安装简介
用户名:mysql
安装目录:/usr/local/mysql-5.5.20
数据库目录:/data/mysql/data
源码包:mysql-5.5.21.tar.gz
自动部署脚本可在 http://linux521.blog.51cto.com/4099846/803623 下载
二、安装准备
添加用户
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 |
1. 命令语法:
重新编译时,需要清除旧的对象文件和缓存信息
# make clean
# rm -f CMakeCache.txt
2.安装选项
CMAKE_INSTALL_PREFIX值是安装的基本目录,其他cmake选项值是不包括前缀,是相对路径名,绝对路径包括 CMAKE_INSTALL_PREFIX路径。如-DINSTALL_SBINDIR=sbin的绝对路径是/usr/local/mysql /sbin
3.存储引擎选项
mysql存储引擎是插件式的,因此插件控制选项可以指定那个存储引擎安装。
configure编译插件选项--with-plugins=csv,myisam,myisammrg,heap,innobase,
archive,blackhole在cmake中没有直接对应的相同选项。对于csv,myisam,myisammrg,heap在cmake中是不需要明确指定存储引擎的名称,因为它们是强制性安装。
可以使用以下选择来安装innodb,archive,blackhole存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
(1可以使用on代替)
如果既不是-DWITH_
4.其他选项
之前MySQL的编译选项大多数都支持。新旧版本之间的安装选项映射成大写字母,删除选项前面破折号,中间字符间的破折号替换成下划线。如:
--with-debug => WITH_DEBUG=1
--with-embedded-server => WITH_EMBEDDED_SERVER
5.调试配置过程
使用configure编译完将生成config.log和config.status文件。
使用cmake编译完在CMakeFiles目录下生成CMakeError.log 和CMakeOutput.log文件。
编译参数参考:
BUILD_CONFIG 采用官方发行版一致的编译参数
CMAKE_BUILD_TYPE 指定产品编译说明信息 RelWithDebInf
CMAKE_INSTALL_PREFIX 指定MySQL安装路径 /usr/local/mysql
CPACK_MONOLITHIC_INSTALL是否建立单个安装包文件 OFF 5.5.7
DEFAULT_CHARSET MYSQL 默认字符集 latin1 5.5.7
DEFAULT_COLLATION MYSQL 默认排序字符集 latin1_swedish_ci 5.5.7
ENABLE_DEBUG_SYNC 是否启用同步调试功能 ON 5.5.7
ENABLE_DOWNLOADS 是否下载可选文件 OFF 5.5.7
ENABLE_DTRACE 是否包含 DTrace 支持 5.5.7
ENABLE_GCOV 是否包含 Gcov 支持 5.5.14
ENABLED_LOCAL_INFILE 是否启用本地 LOAD DATA INFILE OFF 5.5.7
ENABLED_PROFILING 是否启用代码查询分析 ON 5.5.7
INSTALL_BINDIR MySQL 主执行文件目录 PREFIX/bin 5.5.7
INSTALL_DOCDIR 文档安装路径 PREFIX/docs 5.5.7
INSTALL_DOCREADMEDIR 自述文件目录 PREFIX 5.5.7
INSTALL_INCLUDEDIR 头文件目录 PREFIX/include 5.5.7
INSTALL_INFODIR 关于信息文件目录 PREFIX/docs 5.5.7
INSTALL_LAYOUT 选择预定义的安装 STANDALONE 5.5.7
INSTALL_LIBDIR 库文件目录 PREFIX/lib 5.5.7
INSTALL_MANDIR 手册页面目录 PREFIX/man 5.5.7
INSTALL_MYSQLSHAREDIR 共享数据目录 PREFIX/share 5.5.7
INSTALL_MYSQLTESTDIR mysql-test 目录 PREFIX/mysql-test 5.5.7
INSTALL_PLUGINDIR 插件目录 PREFIX/lib/plugin 5.5.7
INSTALL_SBINDIR 服务器超级用户执行文件目录 PREFIX/bin 5.5.7
INSTALL_SCRIPTDIR 脚本目录 PREFIX/scripts 5.5.7
INSTALL_SHAREDIR aclocal/mysql.m4 安装目录 PREFIX/share 5.5.7
INSTALL_SQLBENCHDIR sql-bench 性能测试工具目录 PREFIX 5.5.7
INSTALL_SUPPORTFILESDIR 扩展支持文件目录 PREFIX/support-files 5.5.7
MYSQL_DATADIR 数据库存放目录 5.5.7
MYSQL_MAINTAINER_MODE 是否启用MySQL的维护环境 OFF 5.5.7
MYSQL_TCP_PORT TCP/IP 端口号 3306 5.5.7
MYSQL_UNIX_ADDR Unix Socket 套接字文件 /tmp/mysql.sock 5.5.7
SYSCONFDIR 选项配置文件目录 5.5.7
WITH_COMMENT 编译环境发表评论 5.5.7
WITH_DEBUG 是否包括调试支持 OFF 5.5.7
WITH_EMBEDDED_SERVER 是否要建立嵌入式服务器 OFF 5.5.7
WITH_xxx_STORAGE_ENGINE 静态编译xxx 存储引擎到服务器 5.5.7
WITH_EXTRA_CHARSETS 额外的字符集,包括 all 5.5.7
WITH_LIBWRAP 是否包括支持libwrap(TCP包装) OFF 5.5.7
WITH_READLINE 使用捆绑的readline OFF 5.5.7
WITH_SSL 是否支持SSL no 5.5.7
WITH_ZLIB 是否支持Zlib system 5.5.7
WITHOUT_xxx_