最近在弄配置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