With the document look, quite simple.
#!/bin/bash
# # #2016-3-23
# # #version 1.0
# # # #tishi Yonghu
cat<< AA
You must mv the Mysql_package to/root/tools/.
Aa
Sleep 2
# # #define Var
Tools_dir= "/root/tools"
Package_name= "' CD $tools _dir && ls mysql-*-linux* '"
Version_num= "' CD $tools _dir && ls mysql*linux*-D | Awk-f "-" ' {print $} ' "
Install_path= "/application/mysql$version_num"
# # # #test If have a MySQL user
ID MySQL &>/dev/null
[$?-ne 0] && useradd mysql-s/sbin/login-m && echo "mysql_user OK." | | echo "Mysql_user OK."
# # #test If have a install dir.
[!-D $install _path] && mkdir-p $install _path && echo "install_dir OK." | | (echo "$install _path is exsit."; Exit 1)
# # #tar and MV Mysql_package
CD $tools _dir && tar xf $package _name
Dir_name= "' ls mysql*x86_64-d '"
MV ${dir_name}/* $install _path && sleep 7 && rm-rf ${dir_name} && echo "tar and mv OK." | | Exit 1
# # #ln dir and dir
Ln-s ${install_path}//application/mysql && echo "ln dir OK." | | Exit 1
# # #chown Dir
Chown-r mysql.mysql/application/mysql/&& echo "Chwon dir OK." | | Exit 1
# # #init MySQL
/application/mysql/scripts/mysql_install_db--basedir=/application/mysql/--datadir=/application/mysql/data/-- User=mysql &>/dev/null
[$?-eq 0] && echo "init ok." | | Exit 1
# # #cp MY-CNF
[-F/ETC/MY.CNF] && Mv/etc/my.cnf/etc/my.cnf.bak
Cp/application/mysql/support-files/my-innodb-heavy-4g.cnf/etc/my.cnf
[$?-eq 0] && echo "CP my.cnf OK." | | Exit 1
# # #mysql
Cp/application/mysql/bin/mysqld_safe/application/mysql/bin/mysqld_safe.bak
[$?-ne 0] && exit 1
Sed-i ' S#/usr/local/mysql#/application/mysql#g '/application/mysql/bin/mysqld_safe
[$?-ne 0] && exit 1
grep ' path= '/application/mysql/bin: $PATH "'/etc/profile &>/dev/null
[$?-ne 0] && Echo ' path= "/application/mysql/bin: $PATH" ' >>/etc/profile && source/etc/profile | | echo "Path OK."
[$?-ne 0] && exit 1
#/application/mysql/bin/mysqld_safe & >/dev/null 2>&1
#[$-ne 0] && exit 1
Cp/application/mysql/support-files/mysql.server/etc/init.d/mysqld
[$?-ne 0] && exit 1
Sed-i ' S#/usr/local/mysql#/application/mysql#g '/etc/init.d/mysqld
[$?-ne 0] && exit 1
chmod +x/etc/init.d/mysqld
[$?-ne 0] && exit 1
Chkconfig--add mysqld
[$?-ne 0] && exit 1
grep '/etc/init.d/mysqld start '/etc/rc.local &>/dev/null
[$?-ne 0] && Echo '/etc/init.d/mysqld start ' >>/etc/rc.local
[$?-ne 0] && exit 1
#/application/mysql/bin/mysqladmin-uroot password "123456"
#[$-ne 0] && exit 1
#/application/mysql/binmysql-uroot-p123456
#[$-ne 0] && exit 1
########### #done
echo "Now-can use mysql,thanks for your wait."
This article is from the "10536390" blog, please be sure to keep this source http://10546390.blog.51cto.com/10536390/1754258
Binary installation of MySQL shell script