一鍵部署mysql 無修改直接cp 執行 100% 有效
阿新 • • 發佈:2021-08-24
一鍵部署mysql 無修改直接cp 執行 100% 有效
將安裝包拖至/opt目錄下,編一個指令碼檔案,然後source執行指令碼,等指令碼執行完成,
即可使用mysql -u root -p點選回車即可進入。
#!/bin/bash echo -e "\033[31m =====正在驗證當前為僅主機還是NAT模式===== \033[0m" ping -c1 -W1 www.baidu.com &> /dev/null if [ $? -eq 0 ];then echo -e "\033[31m 檢測當前為NAT模式,為您配置線上yum源 \033[0m" mkdir -p /etc/yum.repos.d/repo.bak mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null yum clean all &> /dev/null yum list &> /dev/null echo -e "\033[31m 線上源已配置完成 \033[0m" else echo -e "\033[31m 檢測當前為僅主機模式,為您配置本地yum源 \033[0m" mount /dev/sr0 /mnt &> /dev/null cd /etc/yum.repos.d/ mkdir -p /etc/yum.repos.d/repo.bak mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null echo '[local] name=local baseurl=file:///mnt enabled=1 gpgcheck=0' > /etc/yum.repos.d/local.repo yum clean all &> /dev/null yum makecache &> /dev/null df -h | grep "/mnt" if [ $? -ne 0 ];then echo -e "\033[31m 檢測當前為僅主機模式,但光碟未連線! \033[0m" else echo -e "\033[31m 本地yum源已配置完成 \033[0m" fi fi #關閉系統防火牆和安全機制 systemctl stop firewalld systemctl disable firewalld setenforce 0 echo -e "\033[31m 檢查安裝包是否正確,請耐心等待 \033[0m" ls /opt | egrep "^mysql-boost-5.7.20.tar.gz$" if [ $? -eq 0 ];then echo -e "\033[31m 接下來進入正式配置,請耐心等待 \033[0m" else echo -e "\033[31m 請準備正確安裝包mysql-boost-5.7.20.tar.gz \033[0m" exit fi #安裝Mysql環境依賴包 yum -y install \ ncurses \ ncurses-devel \ bison \ cmake \ gcc \ gcc-c++ \ make #建立程式使用者,便於準確控制訪問使用者 useradd -M -s /sbin/nologin mysql #編譯安裝 cd /opt tar xzvf mysql-boost-5.7.20.tar.gz -C /opt cd /opt/mysql-5.7.20/ cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ -DSYSCONFDIR=/etc \ -DSYSTEMD_PID_DIR=/usr/local/mysql \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DWITH_BOOST=boost \ -DWITH_SYSTEMD=1 #編譯及安裝 make && make install #修改mysql 配置檔案 echo '[client] port = 3306 socket=/usr/local/mysql/mysql.sock [mysqld] user = mysql basedir=/usr/local/mysql datadir=/usr/local/mysql/data port = 3306 character-set-server=utf8 pid-file = /usr/local/mysql/mysqld.pid socket=/usr/local/mysql/mysql.sock bind-address = 0.0.0.0 skip-name-resolve max_connections=2048 default-storage-engine=INNODB max_allowed_packet=16M server-id = 1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES' > /etc/my.cnf #更改mysql安裝目錄和配置檔案的屬主屬組 chown -R mysql:mysql /usr/local/mysql/ chown mysql:mysql /etc/my.cnf #設定路徑環境變數 echo "export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib">> /etc/profile source /etc/profile #初始化資料庫 cd /usr/local/mysql/bin/ ./mysqld \ --initialize-insecure \ --user=mysql \ --basedir=/usr/local/mysql \ --datadir=/usr/local/mysql/data #新增mysqld系統服務 cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ systemctl daemon-reload systemctl start mysqld.service systemctl enable mysqld
自古英雄多磨難