centos6.5 安装mysql5.6多实例(多配置文件)

前端之家收集整理的这篇文章主要介绍了centos6.5 安装mysql5.6多实例(多配置文件)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。




*********************************************************************

安装说明:

使用镜像: CentOS-6.5-x86_64-minimal.iso

系统 : CentOS release 6.5 (Final)2.6.32-431.el6.x86_64

MysqL 安装目录 /usr/lcoal/MysqL

msyql data目录 /usr/local/MysqL/data/3306

/usr/local/MysqL/data/3307

/usr/local/MysqL/data/3308

************************************************************************

准备工作:

yum -y install lrzsz vim wget tar

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

wget -O /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-6.repo

yum makecache

useradd -M MysqL -s /sbin/nologin

service iptables stop

sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

setenforce 0

chkconfig iptables off

安装依赖包:

yum -y install make gcc gcc-c++ gcc-gfortran flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof

解压包安装MysqL配置工具camke :

tar xf MysqL-5.6.4-m7.tar.gz

tar xf cmake-2.8.5.tar.gz

cd cmake-2.8.5

./configure

gmake

gmake install

开始安装MysqL

cd ../MysqL-5.6.4-m7

cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/MysqL \

-DMysqL_DATADIR=/usr/local/MysqL/data \

-DSYSCONFDIR=/etc -DMysqL_USER=MysqL \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DMysqL_UNIX_ADDR=/usr/local/MysqL/MysqL.sock \

-DMysqL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DMysqL_USER=MysqL -DWITH_DEBUG=0 \

-DWITH_SSL=system

make && make install

多实例开始配置:

cd /usr/local/MysqL/data/

mkdir -p {3306,3307,3308}/data #创建实例数据库目录

chown -R MysqL.MysqL /usr/local/MysqL/ #授权目录权限为MysqL 用户

ln -s /usr/local/MysqL/bin/* /usr/local/sbin/ #MysqL相关命令软连接

cd /usr/local/MysqL/support-files/

cp my-small.cnf ../data/3306/ #拷贝配置文件到实例主目录下面

cp my-small.cnf ../data/3307/

cp my-small.cnf ../data/3308/

更名配置文件

cd ../data/3306

mv my-small.cnf my.cnf

cd ../3307

cd ../3308

初始化数据库

/usr/local/MysqL/scripts/MysqL_install_db �basedir=/usr/local/MysqL �datadir=/usr/local/MysqL/data/3306 �defaults-file=/usr/local/MysqL/data/3306/my.cnf �user=MysqL

/usr/local/MysqL/scripts/MysqL_install_db �basedir=/usr/local/MysqL �datadir=/usr/local/MysqL/data/3307 �defaults-file=/usr/local/MysqL/data/3307/my.cnf �user=MysqL

/usr/local/MysqL/scripts/MysqL_install_db �basedir=/usr/local/MysqL �datadir=/usr/local/MysqL/data/3308 �defaults-file=/usr/local/MysqL/data/3308/my.cnf �user=MysqL

过程中需要看到 有两个OK,说明就是初始化成功了。如有其它报错请检查权限或者百度

修改配置文件

vim /usr/local/MysqL/data/3306/my.cnf

vim /usr/local/MysqL/data/3307/my.cnf

vim /usr/local/MysqL/data/3308/my.cnf

配置文件内容 (基本相同,只需要修改端口,和server-id ,目录文件名称对应即可)

[client]

port = 3306

socket = /usr/local/MysqL/data/3306/MysqL.sock

[MysqLd]

pid-file = /usr/local/MysqL/data/3306/MysqL.pid

datadir = /usr/local/MysqL/data/3306

skip-external-locking

key_buffer_size = 16K

max_allowed_packet = 1M

table_open_cache = 4

sort_buffer_size = 64K

read_buffer_size = 256K

read_rnd_buffer_size = 256K

net_buffer_length = 2K

thread_stack = 128K

server-id = 1

[MysqLdump]

quick

max_allowed_packet = 16M

[MysqL]

no-auto-rehash

[myisamchk]

key_buffer_size = 8M

sort_buffer_size = 8M

[MysqLhotcopy]

interactive-timeout

启动实例:

MysqLd_safe �defaults-file=/usr/local/MysqL/data/3306/my.cnf &

MysqLd_safe �defaults-file=/usr/local/MysqL/data/3307/my.cnf &

MysqLd_safe �defaults-file=/usr/local/MysqL/data/3308/my.cnf &

查看端口状态:

[root@localhost MysqL]# netstat -anpt|grep 330

tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 36275/MysqLd

tcp 0 0 0.0.0.0:3308 0.0.0.0:* LISTEN 36283/MysqLd

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 36328/MysqLd

测试进入数据库

MysqL -uroot -S /usr/local/MysqL/data/3306/MysqL.sock

关闭MysqL数据库实例:

MysqLadmin -uroot -S /usr/local/MysqL/data/3306/MysqL.sock shutdown

MysqLadmin -uroot -S /usr/local/MysqL/data/3307/MysqL.sock shutdown

MysqLadmin -uroot -S /usr/local/MysqL/data/3308/MysqL.sock shutdown

MysqL实例设置密码:

MysqLadmin -uroot -S /usr/local/MysqL/data/3306/MysqL.sock password “root”

MysqLadmin -uroot -S /usr/local/MysqL/data/3307/MysqL.sock password “root”

MysqLadmin -uroot -S /usr/local/MysqL/data/3308/MysqL.sock password “root”

设置密码后进入数据库

MysqL -uroot -proot -S /usr/local/MysqL/data/3306/MysqL.sock

MysqL -uroot -proot -S /usr/local/MysqL/data/3307/MysqL.sock

MysqL -uroot -proot -S /usr/local/MysqL/data/3308/MysqL.sock

设置密码后停止MysqL数据实例:

MysqLadmin -uroot -S/usr/local/MysqL/data/3306/MysqL.sock shutdown -proot

MysqLadmin -uroot -S/usr/local/MysqL/data/3307/MysqL.sock shutdown -proot

MysqLadmin -uroot -S/usr/local/MysqL/data/3308/MysqL.sock shutdown -proot

启动停止脚本 ********************************************************** 启动停止脚本

#!/bin/bash

# name: jinchuang

# QQ : 1054542382

# blog :http://blog.sina.com.cn/jinchuang1025

# MysqL 多实例多配置文件启动脚本

while true

do

color=`echo -e “\033[36m**************************************************** \033[0m”`

echo “”

echo $color

echo “选择 “启动” 还是 “停止” MysqL多实例

1 :启动

2 :停止

3 :退出

read -p “:” m

case $m in

1)

echo “↓↓”

echo “############# MysqL 多实例启动 ################

1 :3306 实例

2 :3307 实例

3 :3308 实例

4 :启动全部实例

5 :退出

回车键返回”

#while true

#do

read -p “请输入实例编号启动:” n

case $n in

# 3306实例启动

MysqLd_safe �defaults-file=/usr/local/MysqL/data/3306/my.cnf 2>&1 >/dev/null &

if [ $? -eq 0 ]

then

echo “3306 实例启动成功”

else

echo “3306 实例启动是败”

fi

;;

#3307实例启动

2)

MysqLd_safe �defaults-file=/usr/local/MysqL/data/3307/my.cnf 2>&1 >/dev/null &

echo “3307 实例启动成功”

echo “3307 实例启动是败”

#3308实例启动

3)

MysqLd_safe �defaults-file=/usr/local/MysqL/data/3308/my.cnf 2>&1 >/dev/null &

echo “3308 实例启动成功”

echo “3308 实例启动是败”

#全部启动

4)

/usr/local/sbin/MysqLd_safe �defaults-file=/usr/local/MysqL/data/3306/my.cnf 2>&1 >/dev/null &

/usr/local/sbin/MysqLd_safe �defaults-file=/usr/local/MysqL/data/3307/my.cnf 2>&1 >/dev/null &

/usr/local/sbin/MysqLd_safe �defaults-file=/usr/local/MysqL/data/3308/my.cnf 2>&1 >/dev/null &

sleep 2 ;

netstat -lntp

#if [ $? -eq 0 ]

# then

# echo “3306,3308 实例启动成功”

# else

#fi

5)

exit 1

#*)

#col=`echo -e “\033[36m请输入正确的编号: \033[0m”`

#echo ” $col!”

#;;

esac

#done

echo “############# MysqL 多实例停止 ################

4 :停止全部实例

read -p “请输入实例编号停止:” n

# 3306实例停止

MysqLadmin -uroot -S /usr/local/MysqL/data/3306/MysqL.sock shutdown -proot

echo “3306 实例停止成功”

echo “3306 实例停止是败”

#3307实例停止

MysqLadmin -uroot -S /usr/local/MysqL/data/3307/MysqL.sock shutdown -proot

echo “3307 实例停止成功”

echo “3307 实例停止是败”

#3308实例停止

MysqLadmin -uroot -S /usr/local/MysqL/data/3308/MysqL.sock shutdown -proot

echo “3308 实例停止成功”

echo “3308 实例停止是败”

#全部停止

a=`MysqLadmin -uroot -S/usr/local/MysqL/data/3306/MysqL.sock shutdown -proot`

b=`MysqLadmin -uroot -S/usr/local/MysqL/data/3307/MysqL.sock shutdown -proot`

c=`MysqLadmin -uroot -S/usr/local/MysqL/data/3308/MysqL.sock shutdown -proot`

$a && $b && $c

netstat -anpt |grep MysqL

echo “3306,3308 实例停止成功”

#echo ” $col!”

done

猜你在找的CentOS相关文章