shell 脚本一键安装mysql数据库(已打包成图形化安装)

编程入门 行业动态 更新时间:2024-10-09 01:18:17

shell 脚本<a href=https://www.elefans.com/category/jswz/34/1767003.html style=一键安装mysql数据库(已打包成图形化安装)"/>

shell 脚本一键安装mysql数据库(已打包成图形化安装)

install_scripts.sh

作用:解压mysql安装包并且注册mysql为一个服务(service),并开机自启动,并且弹出dialog窗体提供安装前配置(用户密码端口配置)。

#!/bin/shinstall_packet_name="mysql"
install_packet_tarball_name=$install_packet_name".tar.gz"
current_install_user="root"
#install_user="mysql"
install_user=$current_install_user
mysql_current_status=0install_path=/usr/local
#mysql_path=/usr/local/${install_packet_name}
mysql_path=/usr/local
#mysql_data_root=~/tdata
mysql_data_root=/tdata
mysql_data_path=$mysql_data_root/data
mysql_sock_path=$mysql_data_root/mysql.sockmysql_user=sean
mysql_port=3306
mysql_passwd=sean
mysql_admin_passwd=123456env_check()
{current_install_user=$(whoami)if [ "$current_install_user" != "root" ]; thenecho "please switch to root user to run this script"exitfiif [ "$install_user" != "root" ]; thenegrep "^$install_user" /etc/group >& /dev/nullif [ $? -ne 0 ]; thengroupadd mysqlfiegrep "^$install_user" /etc/passwd >& /dev/nullif [ $? -ne 0 ];thenuseradd -g mysql mysqlfifi
#    systemctl stop mysql
}mysql_exist_clear()
{systemctl stop mysqltest ! -f /etc/rc.d/init.d/mysql || rm -rf /etc/rc.d/init.d/mysqltest ! -d $mysql_data_root || rm -rf $mysql_data_roottest ! -f /etc/myf || rm -rf /etc/myftest ! -d /usr/local/mysql || rm -rf /usr/local/mysql
}slice_the_files()
{sed -n -e '1,/^Do you understand the feeling of missing someone?$/!p' $0 > $install_path/$install_packet_tarball_name 2>/dev/null
}set_mysql_config()
{cat /dev/null > /tmp/TF_Install.config_dbdialog --title "同方泰德视频平台安装服务(数据库安装)" --form "请输入数据库信息:" 12 40 4  \"数据库连接端口:" 1  1 $mysql_port 1  15  15  0  \"数据库管理员密码:" 2  1 $mysql_admin_passwd 2  15  15  0  \"登录用户名:" 3  1 $mysql_user 3  15  15  0  \"登录密码:"    4   1 $mysql_passwd 4  15  15  0 2> /tmp/TF_Install.config_dbresult=$?if [ $result -eq 1 ]; thenexit 1elif [ $result -eq 255 ]; thenexit 255fimysql_port=$(cat /tmp/TF_Install.config_db |sed -n "1p")mysql_admin_passwd=$(cat /tmp/TF_Install.config_db |sed -n "2p")mysql_user=$(cat /tmp/TF_Install.config_db |sed -n "3p")mysql_passwd=$(cat /tmp/TF_Install.config_db |sed -n "4p")mysql_install_proc
}mysql_install_proc()
{slice_the_filescd ${install_path}tar xzvf $install_packet_tarball_name -C $install_pathif [ $? -ne 0 ]; thenecho -e "\e[1;31m[extract packet failure...]\e[0m"exit 1firm -rf $install_packet_tarball_name
#  chown -R $current_install_user:$current_install_user $install_packet_namechown -R $install_user:$install_user $install_packet_namecd $install_packet_name && cp support-files/my-defaultf ./myfmkdir -p $mysql_data_path
#  chown -R $current_install_user:$current_install_user $mysql_data_rootchown -R $install_user:$install_user $mysql_data_rootsed -i "/mysqld/a\datadir = ${mysql_data_path}"  myfsed -i "/mysqld/a\basedir = ${install_path}/$install_packet_name" myfsed -i "/mysqld/a\user = ${install_user}" myfsed -i "/mysqld/a\character-set-server=utf8" myfsed -i "/mysqld/a\port = ${mysql_port}" myfsed -i "/mysqld/a\socket = ${mysql_sock_path}" myfsed -i "/mysqld/i\[mysql]" myfsed -i "/mysqld/i\default-character-set=utf8" myfsed -i "/mysqld/i\socket = ${mysql_sock_path}" myfsed -i "/mysqld/i\ " myftest ! -f /etc/myf || rm -rf /etc/myfcp myf /etc/myfscripts/mysql_install_db --basedir=$install_path/$install_packet_name --user=$install_user --defaults-file=$install_path/$install_packet_name/myfif [ $? -ne 0 ]; thenecho -e "\e[1;31m[MySQL install init failure...]\e[0m"exit 1ficd $install_path/$install_packet_nameecho "Set mysql as system service"cp support-files/mysql.server /etc/rc.d/init.d/mysqlchmod +x /etc/rc.d/init.d/mysqlchkconfig mysql onsystemctl start mysqlrun_status=$(systemctl status $install_packet_name|grep running)echo $run_statusif [ "$run_status" == "" ]; thenecho -e "\e[1;31m[MySQL start failure...]\e[0m"exit 1elseecho -e "\e[1;32m[MySQL start secessful]\e[0m"fiexport PATH=$PATH:$install_path/$install_packet_name/bin mysql -uroot  -e  "CREATE USER 'sean'@'%' IDENTIFIED BY 'sean';grant all on *.* to 'sean'@'%';CREATE USER 'sean'@'localhost' IDENTIFIED BY 'sean';grant all on *.* to 'sean'@'localhost';flush privileges;"if [ $? -eq 0 ]; thenecho "Set mysql user sean password and create default database successfully!"fiexit 0
}mysql_exist_check()
{run_status=$(systemctl status $install_packet_name|grep running)echo $run_statusif [ "$run_status" != "" ]; then#mysql_current_status=0dialog --title "检测到数据库已经存在" --backtitle "同方泰德视频平台安装服务(数据库安装)" --yesno "是否重新安装?\n" 16 51result=$?if [ $result -eq 1 ];thenexit 1;elif [ $result -eq 255 ];thenexit 255;fiecho "start to downloading.......\n"mysql_exist_clearfiset_mysql_config
}if [ ! -n "$1" ];thengnome-terminal -x bash -c "./同方泰德数据库安装服务\(mysql\).x -r; exec bash;"
elseenv_checkmysql_exist_check  
fi
build_script.sh

作用:构建.x安装文件,使用到了shc命令(具体参考shc加密的使用)来加密上面install_scripts.sh脚本,并且和mysql压缩包(版本mysql-5.6.38-linux-glibc2.12-x86_64.tar)一块打包成为一个可执行文件,注意还有被打包进去的slice.txt文件里面就写了一串英文句子,目的就是sed分离安装包的时候能够以这句话为分割标记点,从而可以分别sed分离出安装包里的脚本文件和压缩包,因此cat写入安装包的时候也是先写入install_scripts.sh脚本,然后是分割标记文件slice.txt,最后才是mysql二进制压缩包。拼接分割文件具体可以参考sed的使用。

#!/bin/shCFLAGS=-static shc -v -r -T -f install_script.sh
cat install_script.sh.x slice.txt mysql.tar.gz > 同方泰德数据库安装服务\(mysql\).x
chmod +x 同方泰德数据库安装服务\(mysql\).x

最后注意的是 .x可执行文件要拷贝到桌面上双击运行,不是桌面下无法弹出窗体。弹出界面后直接输入设定mysql用户名密码和端口,不修改的话就默认下一步就行,一直enter下一步就成功了。 如果提示没有权限就赋读写权限,实在不行用root用户执行。

需要的文件目录


 install_script.sh.x 和install_scripts.sh.x.c是临时文件,是用shc加密 install_script.sh而产生的中间文件,这两个文件不用管,没有用。 有用的就是最下面那个可执行文件,如果要修改安装脚本则修改完install_script.sh文件然后运行build_scripts.sh就会产生新的可执行文件。注意两个脚本文件中  数据库安装服务(mysql).x的名字要一致,改成什么名字看个人需要,其他地方的名字也可以随便改了。 运行效果:

 资源下载地址》》》》》资源下载地址

更多推荐

shell 脚本一键安装mysql数据库(已打包成图形化安装)

本文发布于:2024-02-13 22:15:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1760992.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:一键   脚本   图形化   数据库   shell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!