MYSQL安装信息 MYSQL安装准备 MYSQL安装过程 安装。一键编译部署Mysql。" />

一键编译部署Mysql

#!/bin/bash # 一键安装mysql5.7.35#安装包下载目录 MYSQL_DOWNLOAD_DIR=/data/software/ #数据包目录 MYSQL_INSTALL_DIR=/data/modules/#数据库信息 info_mysql(){ echo "======> MYSQL安装信息 <======"; echo "Mysql版本:5.7.35 "; echo "下载目录:/data/software/ "; echo "安装目录:/data/modules/ "; }#旧版mysql uninstall_mysql(){ echo "\n======> MYSQL安装准备 <======"; echo "残留Mysql检测......." echo "卸载旧版mysql......." echo [+] Uninstall Mysql yum remove mysql* -y yum remove mariadb* -y if [ -f "/etc/my.cnf" ]; then rm -rf /etc/my.cnf fiif [ -f "/root/.mysql_sercret" ]; then rm -rf /root/.mysql_sercret fiif [ -d "/var/lib/mysql" ]; then rm -rf /var/lib/mysql fi if [ -d "/usr/lib64/mysql" ]; then rm -rf /usr/lib64/mysql fi if [ -d "/usr/share/mysql" ]; then rm -rf /usr/share/mysql fi echo "卸载完成!" } #下载mysql IS_CINTINUE='y'; download_mysql(){ echo "安装目录检测......." if [ ! -d "/data/software" ]; then echo "创建下载目录......." mkdir -p /data/software/ fi if [ ! -d "/data/modules/mysql/" ]; then echo "创建数据目录......." mkdir -p /data/modules/ fi echo " 目录准备就绪 !"; echo "======> MYSQL安装过程 <======"; cd /data/software/ read -p " 确认是否安装?【y/n】" IS_CINTINUE if [[ $IS_CINTINUE == 'y' ]]; then echo "请稍等,大约需要20分钟,正在下载MYSQL......."; cd /data/software/ file="/data/software/mysql-boost-5.7.35.tar.gz" if [ ! -f $file ]; then echo "File not found!" yum install -y wget && wget -c https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-5.7.35.tar.gz; echo "下载完成,正在解压......."; tar -zxvf mysql-boost-5.7.35.tar.gz -C /data/modules/ cd /data/modules/ mv /data/modules/mysql-5.7.35/ mysql exit 0 fi echo "解压完成,执行安装......."; #yum install -y wget && wget -c https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.35-el7-x86_64.tar.gz; else echo "请您自行下载安装包!"; exit; fi}#安装mysql install_mysql(){ echo "======> 安装mysql依赖....... <======"; yum -y install gcc gcc-devel gcc-c++ gcc-c++-devel autoconf* automake* zlib* libxmlncurses-devel ncurses libgcrypt libtool* cmake openssl openssl-devel bisonbison-devel perl-Data-Dumper boost boost-doc boost-devel yum -y install gcc make cmake ncurses-devel libxml2-devel libtool-ltdl-devel gcc-c++ autoconf automake bison zlib-devel echo "======> 安装前的设置 <======"; sleep 2s cd /data/modules/mysql/ mkdir data sleep 2s cmake -DCMAKE_INSTALL_PREFIX=/data/modules/mysql/ \ -DMYSQL_DATADIR=/data/modules/mysql/data \ -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \ -DMYSQL_TCP_PORT=3306 \ -DWITH_BOOST=/data/modules/mysql/boost \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci echo "======> 创建mysql用户和组 <======"; cd /data/modules/mysql/ sleep 2s make && make install groupadd mysql && useradd mysql -g mysql -M -s /sbin/nologin && chown mysql:mysql /data/modules/mysql/ # if [ $? -eq 0 ]; then #echo "======> 设置成功!开始编译安装,大约需要20分钟,耐心等待...<======"; #sleep 2s #make && make install #if [ $? -eq 0 ]; then #cd ~ #echo "======> 编译成功!开始设置组和用户! <======"; #sleep 2s #groupadd mysql && useradd mysql -g mysql -M -s /sbin/nologin && chown mysql:mysql /data/modules/mysql/ #else #echo "======> 编译失败! <======"; #exit; #fi #else #echo "======> 设置失败! <======"; #exit; # fi echo "======> 安装完成! <======"; }#配置Mysql configuration_mysql(){echo "======> 配置mysql <======"; cd /data/modules/mysql/ touch mysql.pid echo "10254" > /data/modules/mysql/mysql.pid touch mysql.err touch mysqld.sock chown mysql:mysql /data/modules/mysql/mysql.pid chown mysql:mysql /data/modules/mysql/mysql.err chown mysql:mysql /data/modules/mysql/data/mysqld.sock cat > /etc/my.cnf< 制作服务启动 <======"; cd /data/modules/mysql /bin/cp -rf support-files/mysql.server /etc/init.d/mysqld chmod a+wrx /etc/init.d/mysqld if [ $? -eq 0 ]; then echo "======> 服务设置成功! <======"; cd ~ service mysqld start sleep 2s service mysqld stop sleep 2s else echo "======> 服务设置失败! <======"; fiecho "======> 添加到开机启动项! <======"; chkconfig --add mysqld if [ $? -eq 0 ]; then echo "======> 设置开机启动项成功! <======"; else echo "======> 设置开机启动项失败! <======"; fi service mysqld stop echo "======> 配置环境变量 <======"; echo "export PATH=$PATH:/data/modules/mysql/bin/" >>/etc/profile source /etc/profile echo "启动mysql服务....... "; service mysqld start echo "Mysql已经启动....... "; }#启动数据库设置密码 # mysql_password='123456' # up_mysql(){ #cd /data/modules/mysql/ #echo "======> 请输入数据库密码: <======"; #read -p "输入密码:" -s mysql_password echo #echo password read, is "$mysql_password" ## read -p " 确认是否安装?【y/n】" IS_CINTINUE ## ./bin/mysqladmin -u root password "123456" #if [ $? -eq 0 ]; then #echo "设置root密码成功!"; #else #echo "设置root密码失败!"; #fi #source /etc/profile # }#结束安装 end_mysql(){ echo "运行端口: 3306" echo "数据库用户: mysql" echo "数据库root密码(root@localhost后面):" cat /data/modules/mysql/mysql.err | grep root@localhost: echo "数据库安装路径: /data/modules/mysql/" echo "数据库数据路径: /data/modules/mysql/data" mysql -uroot -p }#安装流程 mysql(){ #数据库信息 info_mysql #旧版数据库卸载 uninstall_mysql #下载数据库 download_mysql #安装数据库 install_mysql #配置数据库 configuration_mysql #数据库以服务启动 service_mysql #启动MySQL设置密码 #显示数据库信息 info_mysql end_mysql} mysql

    推荐阅读