rpm包制作之——mysql-5.7.16

从MySQL 5.7.5开始需要Boost库,也就是因为这个库纠结了好久 )~^~(
By the way,编译过程需要花的时间比较久,对内存和硬盘要求比较高
环境 VM:内存3G,硬盘30G 系统:CentOS release 6.5

mysql-5.7.16源码编译安装

相关依赖安装

# yum -y install make gcc gcc-c++ cmake bison-devel ncurses ncurses-devel perl-JSON perl-devel perl-Time-HiRes

# ntpdate cn.pool.ntp.org
# useradd -M -s /sbin/nologin mysql

从MySQL 5.7.5开始Boost库是必需
Boost库编译安装

./bootstrap.sh
./b2 install threading=multi link=shared

Mysql编译安装

编译
cmake参数: http://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html

# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWIT
H_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DMYSQL_USER=mysql
# make -j3 && make install

# mkdir /var/lib/mysql/
# chown -R mysql:mysql /var/lib/mysql/
# mkdir -p /usr/local/mysql/data
# chown -R mysql:mysql /usr/local/mysql/data

配置文件修改

# vim /etc/my.cnf

[client]
default-character-set=utf8

[mysqld]
datadir=/usr/local/mysql/data
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server=utf8
collation-server=utf8_general_ci
#server-id=1
#log-bin=/tmp/binlog
#log-bin-index=/tmp/binlog.index

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

初始化mysql,记得初始化密码

# bin/mysqld –initialize –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data
# bin/mysqld –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data
# bin/mysql_ssl_rsa_setup
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# service mysqld start

重置密码

# mysql -uroot -p$passwd -e “set password = password(‘*‘)”;

boost_1_59_0 单独rpmbuild

#vim ~/rpmbuild/SPECS/boost.spec

Name:       boost
Version:    1_59_0
Release:    1%{?dist}
Summary:    boost_install

Group:      System Environment/Daemons
License:    GPLv2
URL:        http://www.boost.org/users/history/version_1_59_0.html
Source0:    boost-1_59_0.tar.gz
BuildRoot:   %{_topdir}/%{name}-%{version}-%{release}

BuildRequires:  gcc,make,gcc-c++,bzip2-devel,python-devel,python-libs,libicu-devel
Requires:   bzip2,python-libs  

%description
boost1_59_0 install

%prep
%setup -q


%build
BOOST_ROOT=`pwd`
export BOOST_ROOT
./bootstrap.sh --prefix=%{buildroot}/usr/ --with-toolset=gcc --with-icu
install -d -m 755 %{buildroot}/usr/
./b2 --layout=system install threading=multi link=shared


%clean
rm -rf %{buildroot}

%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig

%files
%defattr(-,root,root,-)
#${_includedir}/boost
/usr/*
%doc
%changelog

mysql-5.7.16 包括boost

# vim ~/rpmbuild/SPECS/mysql.spec

Name:       mysql
Version:    5.7.16
Release:    1%{?dist}
Summary:    mysql_install

Group:      System Environment/Daemons
License:    GPLv2
URL:    http://www.boost.org/users/history/version_1_59_0.html&&http://dev.mysql.com/downloads/mysql/
Source0:    boost_1_59_0.tar.gz
Source1:    %{name}-%{version}.tar.gz
Source2:    my.cnf
BuildRoot:  %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)

BuildRequires:  gcc,make,gcc-c++,cmake,bison-devel,ncurses,ncurses-devel,bzip2-devel,python-devel,python-libs,bzip2,libicu-devel
Requires:   python-libs,bzip2,perl-JSON,perl-Time-HiRes

%description
Build mysql-5.7.16.tar.gz to mysql-5.7.16.rpm

%prep

%setup -q -b 0 -b 1

%build
cd ../boost_1_59_0
BOOST_ROOT=`pwd`
export BOOST_ROOT
./bootstrap.sh --prefix=%{buildroot}/usr/ --with-toolset=gcc --with-icu
install -d -m 755 %{buildroot}/usr/
./b2 install threading=multi link=shared

cd ../mysql-5.7.16
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWI
TH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DMYSQL_USER=mysql
make -j3 %{?_smp_mflags}

%install
make install DESTDIR=%{buildroot}
install -d -m 755 %{buildroot}/usr/
%{__install} -p -D %{SOURCE2} %{buildroot}/etc/my.cnf

%pre
if [ $1 == 1 ];then
    /usr/sbin/useradd mysql -M -s /sbin/nologin 2>/dev/null
fi

%post
if [ $1 == 1 ];then
    mkdir -p /usr/local/mysql/data
    chown -R mysql:mysql /usr/local/mysql/data 2>/dev/null
    /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2>&1 | tee /usr/local/mysql/default-passwd
    #/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2>/dev/null
    /usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data 2>/dev/null
    cp /usr/local/mysql/bin/* /usr/bin/ 2>/dev/null
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 2>/dev/null
    /sbin/chkconfig --add mysqld
    /sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir 2> /dev/null || :
fi

%preun
if [ $1 == 0 ];then
    /usr/sbin/userdel -r mysql 2> /dev/null
    /etc/init.d/mysqld stop > /dev/null 2>&1
    /sbin/chkconfig --del mysqld 2> /dev/null
    /sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir 2> /dev/null || :
fi

%postun
if [ $1 == 0 ];then
    rm -rf /usr/local/mysql 2> /dev/null
    rm -rf /usr/bin/mysql* 2> /dev/null
    rm -rf /etc/my.cnf 2> /dev/null
    rm -rf /etc/init.d/mysqld 2> /dev/null
fi

%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root,-)
/usr/local/mysql/*
/usr/*
%config(noreplace) /etc/my.cnf
%doc

%changelog
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值