安装rpm-build[root@master ~]# yum install rpm-build创建工作目录[root@master ~]# mkdir -p /root/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}[root@master ~]# cp mysql-5.5.27.tar.gz /root/rpmbuild/SOURCES/[root@master ~]# cp my.cnf /root/rpmbuild/SOURCES/[root@master ~]# cp mysqld /root/rpmbuild/SOURCES/[root@master ~]# cd /root/rpmbuild/SPECS/[root@master SPECS]# vim mysql.spec Name: mysqlVersion: 5.5.27Release: 1%{?dist}Summary: mysql-5.5.27.tar.gz to mysql-5.5.27.rpmGroup: Applications/ArchivingLicense:GPLURL: http://www.cnblogs.com/kingtigerhuVendor: knightSource0: %{name}-%{version}.tar.gzSource1: mysqldSource2: my.cnfBuildRequires: cmakeRequires: ncurses-develAutoreq: noAutoprov : no%descriptionBuild mysql-5.5.27.tar.gz to mysql-5.5.27.rpm%prep%setup -q%build//编译的时候会报错,所以把%configure删除了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 \-DWITH_READLINE=1 \-DMYSQL_TCP_PORT=3306 \-DENABLED_LOCAL_INFILE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DEXTRA_CHARSETS=all \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci make %{?_smp_mflags}%installrm -rf %{buildroot}make install DESTDIR=%{buildroot}%{__install} -p -D -m 0755 %{SOURCE1} %{buildroot}/etc/rc.d/init.d/mysqld%{__install} -p -D %{SOURCE2} %{buildroot}/etc/my.cnf%pre//$1有3个值,代表动作,安装类型,1表示安装,2表示升级,0表示卸载if [ $1 == 1 ];then /usr/sbin/useradd mysql 2> /dev/nullfi%postif [ $1 == 1 ];then /sbin/chkconfig --add mysqld /sbin/chkconfig mysqld on echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile source /etc/profile chown -R mysql:mysql /usr/local/mysql /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data > /dev/null 2>&1fi%preunif [ $1 == 0 ];then /usr/sbin/userdel mysql 2> /dev/null /etc/init.d/mysqld stop > /dev/null 2>&1fi%postun%cleanrm -rf %{buildroot}%files%defattr(-,root,root,0755)/usr/local/mysql/%attr(0755,root,root) /etc/rc.d/init.d/mysqld%config(noreplace) /etc/my.cnf%doc%changelog* Thu May 12 2016 knight <1908616619@qq.com> - 5.5.27-1- Initial version[root@master SPECS]# rpmbuild -bb mysql.spec [root@master SPECS]# ll /root/rpmbuild/RPMS/x86_64/mysql-*-rw-r--r-- 1 root root 28426984 5月 12 04:16 /root/rpmbuild/RPMS/x86_64/mysql-5.5.27-1.el6.x86_64.rpm[root@slave2 ~]# rpm -ivh mysql-5.5.27-1.el6.x86_64.rpm --nodeps --forcePreparing... ########################################### [100%] 1:mysql ########################################### [100%][root@slave2 ~]# Installing MySQL system tables...OKFilling help tables...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/usr/local/mysql/bin/mysqladmin -u root password 'new-password'/usr/local/mysql/bin/mysqladmin -u root -h slave2 password 'new-password'Alternatively you can run:/usr/local/mysql/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd /usr/local/mysql/mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr/local/mysql/scripts/mysqlbug script!rpm包安装的时候会显示这些信息,但是不影响,不知道怎么屏蔽这些信息,求指教