脚本安装
#!/bin/bashecho "-----------------------start install mysql----------------------"#安装必要的包yum -y install gcc gcc-c++ ncurses openssl openssl-devel make kernel-devel m4 ncurses-devel libtool* #创建数据存放文件mkdir -p /data/dbdata#检查mysql组及用户是否存储,不存储则创建if [ `grep "mysql" /etc/passwd | wc -l` -eq 0 ];thenecho "adding user mysql"/usr/sbin/groupadd mysql/usr/sbin/useradd -g mysql mysqlelseecho "mysql user is exist"fi#下载mysql5.1tar包wget echo "tar xzvf mysql-5.1.63.tar.gz"#解压tar包tar xzvf mysql-5.1.63.tar.gz#进入安装目录进行安装cd mysql-5.1.63echo "configuring mysql,please wait-----------------"#进行编译配置prefix为软件安装目录,localstatedir为数据存放目录等./configure '--prefix=/usr/local/mysql' '--localstatedir=/data/dbdata/' '--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock' '--with-charset=utf8' '--with-extra-charsets=complex' '--with-pthread' '--enable-thread-safe-client' '--with-ssl' '--with-client-ldflags=-all-static' '--with-mysqld-ldflags=-all-static' '--with-plugins=partition,federated,innobase,csv,blackhole,myisam,innodb_plugin,heap,archive' '--enable-shared' '--enable-assembler'if [ $? -ne 0 ];then
echo "configure filed ,please check it out!"exit 1fi#编辑echo "make mysql, please wait for 20 minutes"makeif [ $? -ne 0 ];thenecho "make filed ,please check it out!"exit 1fi#编译安装make install#更改相关目录权限chown -R mysql:mysql /usr/local/mysqlchown -R mysql.mysql /data/dbdata/#创建系统数据表/usr/local/mysql/bin/mysql_install_db --user=mysqlcp ../my.cnf /etc/my.cnf
cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqldchkconfig --level 2345 mysqld oncp /usr/local/mysql/bin/mysql* /usr/bin/echo "mysql starting"/etc/rc.d/init.d/mysqld startif [ $? -ne 0 ];thenecho "mysql start filed ,please check it out!"elseecho "mysql start successful,congratulations!"fi