mysql5.6二进制包,MySQL 5.6版本二进制包多实例安装

一、环境介绍

(1)系统环境介绍:

[root@linux-node2 ~]# uname -a

Linux linux-node2 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

[root@linux-node2 ~]# cat /etc/redhat-release

CentOS Linux release 7.4.1708 (Core)

(2)MySQL 5.6.x版本下载

下载地址:http://mirrors.sohu.com/mysql/MySQL-5.6/

二、MySQL安装

(1)解压

[root@linux-node2 ~]# tar -zxvf mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz -C /usr/local/mysql-5.6.12

(2)创建软链接

[root@linux-node2 ~]# ln -sv /usr/local/mysql-5.6.12 /usr/local/mysql

(3)创建mysql 用户

[root@linux-node2 ~]# useradd -M -s /sbin/nologin mysql

(4)创建目录结构和授权

[root@linux-node2 ~]# mkdir /data/{3306,3307}/ -p

[root@linux-node2 ~]# chown -R mysql.mysql /data

(5)初始化数据库

[root@linux-node2 ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data

[root@linux-node2 ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3307/data

(6)修改配置

[root@linux-node2 mysql]# vim /data/3306/my.cnf

[client]

port = 3306

socket = /data/3306/mysql3306.sock

[mysqld]

port = 3306

socket = /data/3306/mysql3306.sock

datadir = /data/3306/data

[root@linux-node2 mysql]# vim /data/3307/my.cnf

[client]

port = 3307

socket = /data/3307/mysql3307.sock

[mysqld]

port = 3307

socket = /data/3307/mysql3307.sock

datadir = /data/3307/data

(7)启动多实例

[root@linux-node2 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf &

[root@linux-node2 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf &

[root@linux-node2 mysql]# netstat -tulnp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1865/nginx: worker

tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN 1865/nginx: worker

tcp 0 0 0.0.0.0:8082 0.0.0.0:* LISTEN 1865/nginx: worker

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 866/sshd

tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2235/master

tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 22597/php-fpm: mast

tcp6 0 0 :::3307 :::* LISTEN 11221/mysqld

tcp6 0 0 :::22 :::* LISTEN 866/sshd

tcp6 0 0 ::1:25 :::* LISTEN 2235/master

tcp6 0 0 :::3306 :::* LISTEN 10903/mysqld

(8)修改密码

[root@linux-node2 ~]# mysqladmin -u root password "123456" -S /data/3306/mysql3306.sock

[root@linux-node2 ~]# mysqladmin -u root password "654321" -S /data/3307/mysql3307.sock

(9)登陆数据库

[root@linux-node2 ~]# mysql -uroot -p -S /data/3306/mysql3306.sock

Enter password:

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.12 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> quit;

Bye

[root@linux-node2 ~]# mysql -uroot -p -S /data/3307/mysql3307.sock

Enter password:

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.12 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> quit;

Bye

三、MySQL多实例启动脚本

[root@linux-node2 ~]# cat /data/3306/mysql

#!/bin/sh

#init

port=3306

mysql_user="root"

mysql_pwd="123456"

CmdPath="/usr/local/mysql/bin"

mysql_sock="/data/${port}/mysql3306.sock"

#startup function

function_start_mysql()

{

if [ ! -e "$mysql_sock" ];then

printf "Starting MySQL...\n"

${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null &

else

printf "MySQL is running...\n"

exit

fi

}

#stop function

function_stop_mysql()

{

if [ ! -e "$mysql_sock" ];then

printf "MySQL is stopped...\n"

exit

else

printf "Stoping MySQL...\n"

${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql3306.sock shutdown

fi

}

#restart function

function_restart_mysql()

{

printf "Restarting MySQL...\n"

function_stop_mysql

sleep 2

function_start_mysql

}

case $1 in

start)

function_start_mysql

;;

stop)

function_stop_mysql

;;

restart)

function_restart_mysql

;;

*)

printf "Usage: /data/${port}/mysql {start|stop|restart}\n"

esac

[root@linux-node2 ~]# cat /data/3307/mysql

#!/bin/sh

#init

port=3307

mysql_user="root"

mysql_pwd="654321"

CmdPath="/usr/local/mysql/bin"

mysql_sock="/data/${port}/mysql3307.sock"

#startup function

function_start_mysql()

{

if [ ! -e "$mysql_sock" ];then

printf "Starting MySQL...\n"

${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null &

else

printf "MySQL is running...\n"

exit

fi

}

#stop function

function_stop_mysql()

{

if [ ! -e "$mysql_sock" ];then

printf "MySQL is stopped...\n"

exit

else

printf "Stoping MySQL...\n"

${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql3307.sock shutdown

fi

}

#restart function

function_restart_mysql()

{

printf "Restarting MySQL...\n"

function_stop_mysql

sleep 2

function_start_mysql

}

case $1 in

start)

function_start_mysql

;;

stop)

function_stop_mysql

;;

restart)

function_restart_mysql

;;

*)

printf "Usage: /data/${port}/mysql {start|stop|restart}\n"

esac

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值