一鍵安裝mysql的指令碼

來源:互聯網
上載者:User

標籤:mysql   local   使用者 一鍵安裝   

最近在弄配置mysql的主從測試,老是重複安裝mysql

所以做了個指令碼,mysql流程是參考別人的

但是shell是自己寫的


#!/bin/bash

#切換到下載目錄

cd /usr/local/src

#下載免免編譯的包

wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz

#解壓

tar zxvf mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz

#移動解壓的檔案到安裝目錄

mv mysql-5.6.29-linux-glibc2.5-x86_64 /usr/local/mysql

#建立使用者

useradd -s /sbin/nologin mysql

#切換到安裝目錄

cd /usr/local/mysql

#建立mysql資料存放區目錄並將該目錄設定為mysql的用和組

mkdir -p /data/mysql ; chown -R mysql.mysql /data/mysql

#執行初始化安裝,定義使用者為mysql 資料存放區目錄

./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

#複製開機檔案到init目錄,並給執行許可權

cp support-files/mysql.server  /etc/init.d/mysqld

chmod 755 /etc/init.d/mysqld

#建立/etc/my.cnf 引號後面的內容可以自己根據自己情況修改

echo "# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It‘s a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of MySQL.


[mysqld]


# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M


# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

log_bin=mysql-bin


# These are commonly set, remove the # and set as required.

basedir = /usr/local/mysql

datadir = /data/mysql

port = 3306

server_id = 1

socket = /data/mysql/mysql.sockt


# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M


sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

" >/etc/my.cnf

#修改開機檔案的程式安裝目錄和資料存放區目錄(根據不同的版本這個位置可能有區別)

sed -i ‘46c  basedir=/usr/local/mysql‘ /etc/init.d/mysqld

sed -i ‘47c  datadir=/data/mysql‘ /etc/init.d/mysqld

#增加為服務,並設定開機啟動

#啟動mysql

chkconfig --add mysqld

chkconfig mysqld on

service mysqld start



測試通過環境為centos6.4_64

本文出自 “dessler” 部落格,請務必保留此出處http://312636.blog.51cto.com/302636/1772467

一鍵安裝mysql的指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.