#!/bin/bash
rpm -qa | grep mysql > /dev/null
if [ $? = 0 ]
then
cd /usr/local/src/mysql-5.1.62/
make uninstall
fi
yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml3 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel libmcrypt openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libtool libtool-ltdl-devel fontconfig fontconfig-devel libxslt libxslt-devel gettext gettext-devel libXpm-devel libevent-devel net-snmp net-snmp-devel ImageMagick-devel ncurses-devel.x86_64 > /dev/null
# 解压mysql数据包并到相应的文件夹中。
tar zxf /root/mysql-5.1.62.tar.gz -C /usr/local/src
cd /usr/local/src/mysql-5.1.62
# 创建数据库的存储文件目录。
if [ -d /data/mysql ]
then
useradd -u 27 -d /data/mysql/ -s /sbin/nologin mysql
chown -R mysql.mysql /data/mysql
else
mkdir -p /data/mysql
useradd -u 27 -d /data/mysql/ -s /sbin/nologin mysql
chown -R mysql.mysql /data/mysql
fi
#初始化并指定安装路径和相应的字符集。
/usr/local/src/mysql-5.1.62/configure --prefix=/usr/local/mysql \
--datadir=/data/mysql --with-charsel=utf8 \
--with-extra-charsets=gbk,gb2312,utf8,ascii
#编译并安装
make
make install
#复制样本文件做配置文件
cp /usr/local/src/mysql-5.1.62/support-files/my-medium.cnf /etc/my.cnf
#指定mysql二进制文件目录
cat << ok >> /etc/my.cnf
datadir =/data/mysql
ok
#运行安装脚本并指定相关文件的路径。
/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/
#复制mysql服务脚本文件到/etc/init.d/mysqld
cp /usr/local/src/mysql-5.1.62/support-files/mysql.server /etc/init.d/mysqld
#给启动脚本加可执行权限。
#在mysql配置文件中添加mysql的二进制文件目录
cat << ok >> /etc/my.cnf
[mysqld]
datadir =/data/mysql
ok
chmod +x /etc/init.d/mysqld
#定义bash
cat << qq >> /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
qq
#重读文件让profile刷新
. /etc/profile
#启动服务
/etc/init.d/mysqld restart
chkconfig mysqld on
阅读(1078) | 评论(0) | 转发(0) |