MySQL 5.6版本二进制包多实例安装

一、环境介绍

(1)系统环境介绍:
[[email protected] ~]# 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
[[email protected] ~]# 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)解压

[[email protected] ~]# tar -zxvf mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz -C /usr/local/mysql-5.6.12

(2)创建软链接

[[email protected] ~]# ln -sv /usr/local/mysql-5.6.12 /usr/local/mysql

(3)创建mysql 用户

[[email protected] ~]# useradd -M -s /sbin/nologin mysql

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

[[email protected] ~]# mkdir /data/{3306,3307}/ -p
[[email protected] ~]# chown -R mysql.mysql /data

(5)初始化数据库

[[email protected] ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data
[[email protected] ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3307/data

(6)修改配置

[[email protected] 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

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

[[email protected] mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf &
[[email protected] mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf &
[[email protected] 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)修改密码

[[email protected] ~]# mysqladmin -u root password "123456" -S /data/3306/mysql3306.sock
[[email protected] ~]# mysqladmin -u root password "654321" -S /data/3307/mysql3307.sock

(9)登陆数据库

[[email protected] ~]# 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
[[email protected] ~]# 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多实例启动脚本

[[email protected] ~]# 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
[[email protected] ~]# 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

原文地址:http://blog.51cto.com/jinlong/2059076

时间: 2024-11-06 07:27:11

MySQL 5.6版本二进制包多实例安装的相关文章

Mysql 5.6版本二进制安装

时间:2018.7.30作者:李强参考:man,info,magedu讲义,万能的internet实验环境:VMware? Workstation 12 Pro ,Centos 6.9,Centos 7.4,SecureCRT Version 8.1.4声明:以下英文纯属个人翻译,英文B级,欢迎纠正,以下内容纯属个人理解,并没有对错,只是参考,盗版不纠,才能有限,希望不误人子弟为好.版本:v1-2018.7.30 参考资料 1.https://www.cnblogs.com/BrightMoon

MySQL 5.6.35 RPM包方式的安装

Mysql 5.6.35版本 RPM包方式的安装 一.删除旧的RPM包: 查询 rpm -qa | grep -i mysql如果有需要先删除rpm -ev mysql-libs- --nodepsrpm -e --nodeps mysql-devel-5.1.73rpm -e --nodeps mysql-5.1.73*加--nodeps是强力删除 二.在安装要确保先禁用selinux,关闭防火墙iptables 禁用selinux临时禁用命令setenforce 0 永久禁用使用文本编辑工具

mysql5.7 基于二进制编译多实例安装

mysql5.7 基于二进制编译多实例安装 cd /usr/local/src/wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gztar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz mv mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz /usr/local/mysql创建

mysql 5.7.14二进制包安装

操作系统版本: [[email protected] ~]# cat /etc/redhat-release CentOS release 6.5 (Final) 操作系统内核: [[email protected] ~]# uname -r 2.6.32-431.el6.x86_64 关闭防火墙并关闭自启动: [[email protected] ~]# /etc/init.d/iptables stop [[email protected] ~]# chkconfig --level 234

CentOS7/64位环境安装Mysql 5.7.19二进制包教程

1.下载mysql 在官网:http://dev.mysql.com/downloads/mysql/ 中,选择二进制的mysql版本下载: #wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz 2.解压 #tar -xzvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz  --解压 #mv mysql-5.7.18-lin

Linux 二进制包安装MySQL的一些问题

第一步:安装相关的依赖yum install perl-Data-Dumper 第二步:初始化mysql数据库的内部信息./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ------------------ 二进制包是否可以成功的运行,与先前是否先解决rpm包的依赖无关. 也就是说,就算rpm包安装不上,二进制包还是可以安装上去并且正常运行的. ---------------

MySQL二进制包安装并自定义basedir

前言: MySQL二进制包,定死了basedir为/usr/local/mysql/,但是很多人喜欢自定义目录,比如我就喜欢放/opt/app/mysql 数据目录喜欢自定义为/data/mydata/,以前必须把basedir必须做个软链接到/usr/local/mysql,本人有轻微的强迫症,就不想这么做,下面就来看实现过程. 1创建组,创建用户 groupadd -g3306 mysql useradd -u3306 -M -s /sbin/nologin mysql 2.解压二进制包,创

Linux下MySQL5.7.18二进制包安装(无默认配置文件my_default.cnf)

本文出处:http://www.cnblogs.com/wy123/p/6815049.html 最新在学习MySQL,纯新手,对Linux了解的也不多,因为是下载的最新版的MySQL(MySQL5.7.18)二进制包,CentOS7.2下测试安装,方便以后折腾.大概步骤如下,安装删除反复折腾了几遍,按照以下步骤,应该没啥问题了.也没有想象中的复杂,大部分步骤都是参考网上的,照做就是了,出错的话,多尝试,多查资料. 操作系统版本 创建mysql组和用户 下载最新版的MySQL 5.7.18二进制

MySQL多实例安装

    MySQL数据库(一) 作者:Jack 归档:学习笔记 2017/6/19 目  录 MySQl数据库(一)... 3 第1章概述:... 4 1.1 MySQL介绍:... 4 1.2 MariaDB数据库的诞生背景介绍... 4 1.3 MySQL多实例介绍... 5 1.3.1 什么是MySQL多实例... 5 1.3.2 MySQL多实例的作用与问题... 6 1.4 MySQL多实例的生产应用场景... 7 第2章关系型数据库与非关系型数据库... 8 2.1 关系型数据库..