Linux下mysql5.6.24(二進制)自動安裝腳本
本文為大家分享了Linux環(huán)境下mysql5.6.24自動安裝腳本代碼,供大家參考,具體內(nèi)容如下
說明:
一、本腳本僅供測試使用,若正式環(huán)境想要使用,需更改腳本的一些參數(shù)。
二、使用本腳本之前,需保證linux環(huán)境可以聯(lián)網(wǎng)下載,若不能聯(lián)網(wǎng),則需要將下載好的mysql二進制包上傳至linux中的/data目錄下。
三、腳本使用是需一次輸入三個參數(shù):
1、需安裝的mysql版本號,如:5.6.24
2、需安裝的mysql端口設(shè)置,如:3306
3、mysql的server_id設(shè)置,如:1003306
使用步驟:
1、將下列腳本上傳至linux環(huán)境中,我個人是以mysql_install.sh命名
#!/bin/bash #mysql_install by chen #Email:chenhz1218@gmail.com & 296966488@qq.com #version 2.0 #安裝版本 5.6.20-5.6.25 #安裝要求: #需要可以聯(lián)網(wǎng),若無網(wǎng)絡(luò),可以先創(chuàng)建/data目錄,將安裝包上傳到/data目錄下 #判斷/data目錄是否存在,若不存在則創(chuàng)建,并且下載mysql datamenu="/data" read -p "Input a mysql version:" -t 30 mysql_version read -p "Input a mysql port:" -t 30 mysql_port read -p "Input a mysql_server_id:" -t 30 mysql_server_id mysqlfile="$datamenu/mysql-$mysql_version-linux-glibc2.5-x86_64.tar.gz" if [ ! -d "$datamenu" ];then mkdir "$datamenu" wget -P /data http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-$mysql_version-linux-glibc2.5-x86_64.tar.gz elif [ ! -f "$mysqlfile" ];then wget -P /data http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-$mysql_version-linux-glibc2.5-x86_64.tar.gz fi #解壓下載好的mysql cd /opt mkdir mysql cd mysql tar zxvf $mysqlfile -C /opt/mysql #創(chuàng)建mysql用戶 egrep "^mysql" /etc/group >& /dev/null if [ $? -ne 0 ] then groupadd mysql fi #create user if not exists egrep "^mysql" /etc/passwd >& /dev/null if [ $? -ne 0 ] then useradd -g mysql -s /sbin/nologin -d /usr/local/mysql mysql fi #創(chuàng)建mysql軟連接,并授權(quán)給mysql用戶 cd /usr/local/ rm -rf /usr/local/mysql ln -s /opt/mysql/mysql-$mysql_version-linux-glibc2.5-x86_64 /usr/local/mysql chown -R mysql:mysql /usr/local/mysql chown -R mysql:mysql /usr/local/mysql/ #基于配置文件,創(chuàng)建mysql安裝目錄,并授權(quán) mkdir -p /data/mysql mkdir -p /data/mysql/mysql${mysql_port} cd /data/mysql/mysql${mysql_port}/ mkdir /data/mysql/mysql${mysql_port}/data mkdir /data/mysql/mysql${mysql_port}/logs mkdir /data/mysql/mysql${mysql_port}/tmp chown -R mysql:mysql /data/mysql/mysql${mysql_port} cat > /etc/my.cnf << EOF [client] port = ${mysql_port} socket = /tmp/mysql.sock # The MySQL server [mysqld] # Basic port = ${mysql_port} user = mysql basedir = /usr/local/mysql datadir = /data/mysql/mysql${mysql_port}/data tmpdir = /data/mysql/mysql${mysql_port}/tmp socket = /tmp/mysql.sock log-bin = /data/mysql/mysql${mysql_port}/logs/mysql-bin log-error = error.log slow-query-log-file = slow.log skip-external-locking skip-name-resolve log-slave-updates lower_case_table_names = 1 #忽略表名大小寫 character_set_server = gbk innodb_file_per_table = 1 innodb_autoinc_lock_mode = 2 explicit_defaults_for_timestamp = true sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES EOF #初始化mysql cd /usr/local/mysql ./scripts/mysql_install_db --defaults-file=/etc/my.cnf #在/etc/init.d下創(chuàng)建mysql 啟動腳本 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql #添加環(huán)境變量,并使/etc/profile環(huán)境變量生效 echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
export PATH=$PATH:/usr/local/mysql/bin
2、給腳本賦予可執(zhí)行權(quán)限,
[root@zabbix-server ~]# rz -y z waiting to receive.**B0100000023be50 [root@zabbix-server ~]# ls anaconda-ks.cfg install.log install.log.syslog mysql_install.sh [root@zabbix-server ~]# chmod +x mysql_install.sh [root@zabbix-server ~]# ls -al|grep mysql_install.sh -rwxr-xr-x. 1 root root 3136 Jul 29 10:29 mysql_install.sh
3、執(zhí)行腳本,并輸入三個參數(shù),等待數(shù)據(jù)庫安裝
[root@MySQL ~]# ./mysql_install.sh Input a mysql version:5.6.24 Input a mysql port:3306 Input a mysql_server_id:1003306
4、啟動數(shù)據(jù)庫
[root@MySQL ~]# /etc/init.d/mysql start Starting MySQL.. [ OK ] [root@zabbix-server ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.24-log MySQL Community Server (GPL) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases -> ; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) mysql>
至此,linux下mysql安裝已經(jīng)完成,可以使用它做一些測試了。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
使用SQL語句統(tǒng)計數(shù)據(jù)時sum和count函數(shù)中使用if判斷條件的講解
今天小編就為大家分享一篇關(guān)于使用SQL語句統(tǒng)計數(shù)據(jù)時sum和count函數(shù)中使用if判斷條件的講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-02-02SQL實現(xiàn)LeetCode(176.第二高薪水)
這篇文章主要介紹了SQL實現(xiàn)LeetCode(176.第二高薪水),本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-08-08用批處理實現(xiàn)自動備份和清理mysql數(shù)據(jù)庫的代碼
有網(wǎng)友問我在win2003下如何自動備份MySQL數(shù)據(jù)庫,既然是自動備份,那肯定得寫腳本,當(dāng)然我們也可以利用軟件實現(xiàn)2013-08-08用Eclipse連接MySQL數(shù)據(jù)庫的步驟
這篇文章主要介紹了如何用Eclipse連接MySQL數(shù)據(jù)庫,需要的朋友可以參考下2015-08-08從云數(shù)據(jù)遷移服務(wù)看MySQL大表抽取模式的原理解析
這篇文章主要介紹了從云數(shù)據(jù)遷移服務(wù)看MySQL大表抽取模式的原理解析,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-02-02