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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.repo http://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

mv my-small.cnf my.cnf

cd ../3308

mv my-small.cnf my.cnf

 

初始化数据库:

 

/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]

port                = 3306

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

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 &

 

查看端口状态:

 

[[email protected] 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实例启动

1)

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 &

if [ $? -eq 0 ]

then

echo “3307 实例启动成功”

else

echo “3307 实例启动是败”

fi

;;

#3308实例启动

3)

mysqld_safe –defaults-file=/usr/local/mysql/data/3308/my.cnf 2>&1 >/dev/null &

if [ $? -eq 0 ]

then

echo “3308 实例启动成功”

else

echo “3308 实例启动是败”

fi

;;

#全部启动

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,3307,3308 实例启动成功”

#    else

#        echo “3306,3307,3308 实例启动是败”

#fi

;;

5)

exit 1

;;

#*)

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

#echo        ”        $col!”

#;;

esac

#done

;;

2)

echo “↓↓”

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

1 :3306 实例

2 :3307 实例

3 :3308 实例

4 :停止全部实例

5 :退出

回车键返回”

#while true

#do

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

case $n in

# 3306实例停止

1)

mysqladmin -uroot -S /usr/local/mysql/data/3306/mysql.sock shutdown -proot

if [ $? -eq 0 ]

then

echo “3306 实例停止成功”

else

echo “3306 实例停止是败”

fi

;;

#3307实例停止

2)

mysqladmin -uroot -S /usr/local/mysql/data/3307/mysql.sock shutdown -proot

if [ $? -eq 0 ]

then

echo “3307 实例停止成功”

else

echo “3307 实例停止是败”

fi

;;

#3308实例停止

3)

mysqladmin -uroot -S /usr/local/mysql/data/3308/mysql.sock shutdown -proot

if [ $? -eq 0 ]

then

echo “3308 实例停止成功”

else

echo “3308 实例停止是败”

fi

;;

#全部停止

4)

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

if [ $? -eq 0 ]

then

netstat -anpt |grep mysql

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

else

echo “3306,3307,3308 实例停止是败”

fi

;;

5)

exit 1

;;

#*)

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

#echo    ”       $col!”

#;;

esac

#done

;;

3)

exit 1

;;

esac

done


本文出自 “jinchuang” 博客,请务必保留此出处http://jinchuang.blog.51cto.com/8690689/1844379

以上是关于centos6.5 安装mysql5.6多实例(多配置文件)的主要内容,如果未能解决你的问题,请参考以下文章

在centos6,5(64位)系统安装多实例mysql5.6

CentOS6.5源码安装多个MySQL实例及复制搭建

安装mysql5.6和多实例配置

MySQL5.6多实例安装

MySQL5.6多实例部署

MySQL5.6多实例部署