MariaDB資料庫安裝指令碼
阿新 • • 發佈:2019-02-04
一、指令碼安裝
1、新建一個指令碼 name.sh (name可以隨便寫)
vi name.sh
新增指令碼內容:
#!/bin/bash echo '資料庫安裝指令碼開始執行' file='/etc/yum.repos.d/MariaDB.repo' if [ ! -f "${file}" ];then echo 'MariaDB.repo檔案不存在' touch ${file} echo '建立MariaDB.repo檔案' else echo 'MariaDB.repo檔案已存在' rm -rf ${file} echo '刪除MariaDB.repo檔案' touch ${file} echo '建立MariaDB.repo檔案' fi echo 'MariaDB.repo檔案新增內容開始' echo '[mariadb]' > ${file} echo 'name = MariaDB' >> ${file} echo 'baseurl = http://yum.mariadb.org/10.2/centos7-amd64' >> ${file} echo 'gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB' >> ${file} echo 'gpgcheck=1' >> ${file} echo 'MariaDB.repo檔案新增內容結束' cat ${file} echo 'yum安裝MariaDB開始' yum install MariaDB-server MariaDB-client -y systemctl start mariadb systemctl enable mariadb systemctl status mariadb echo 'yum安裝MariaDB結束' echo '資料庫安裝指令碼執行結束'
最後 :wq儲存內容
2、賦權
chmod 777 name.sh
3、執行指令碼
./name.sh
4、連線資料庫
mysql -u root -p
預設密碼為空,直接回車即可