MySQL 5.6 Version Binary package multi-instance installation

Source: Internet
Author: User
Tags create directory

I. Introduction to the Environment
(1)系统环境介绍:[[email protected] ~]# uname -aLinux 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/
Second, MySQL installation

(1) Decompression
[[email protected] ~]# tar -zxvf mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz -C /usr/local/mysql-5.6.12
(2) Create a soft link
[[email protected] ~]# ln -sv /usr/local/mysql-5.6.12 /usr/local/mysql
(3) Create a MySQL user
[[email protected] ~]# useradd -M -s /sbin/nologin mysql
(4) Create directory structure and authorization
[[email protected] ~]# mkdir /data/{3306,3307}/ -p[[email protected] ~]# chown -R mysql.mysql /data
(5) Initializing the database
[[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) Modify the configuration
[[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) Start multi-instance
[[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-tulnpactive Internet connections (only servers) Proto recv-q send-q Local Address for Eign Address State Pid/program name TCP 0 0 0.0.0.0:80 0.0.0.0:* L  Isten 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:::* LI         STEN 10903/mysqld
(8) Change Password
[[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) Login Database
[[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 2Server 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 2Server 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
Third, MySQL multi-instance startup script
  [[email protected] ~]# cat/data/3306/mysql#!/bin/sh#initport=3306mysql_user= "root" mysql_pwd= " 123456 "cmdpath="/usr/local/mysql/bin "mysql_sock="/data/${port}/mysql3306.sock "#startup Functionfunction_start_ MySQL () {if [!-e "$mysql _sock"];thenprintf "Starting mysql...\n" ${cmdpath}/mysqld_safe--defaults-file=/data/${port} /MY.CNF 2>&1 >/dev/null &elseprintf "MySQL is running...\n" Exitfi} #stop Functionfunction_stop_mysql () { if [!-e "$mysql _sock"];thenprintf "MySQL is stopped...\n" exitelseprintf "stoping mysql...\n" ${cmdpath}/mysqladmin-u ${ Mysql_user}-p${mysql_pwd}-s/data/${port}/mysql3306.sock Shutdownfi} #restart functionfunction_restart_mysql () { printf "Restarting mysql...\n" Function_stop_mysqlsleep 2function_start_mysql}case instart) 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#initport=3307mysql_user="root"mysql_pwd="654321"CmdPath="/usr/local/mysql/bin"mysql_sock="/data/${port}/mysql3307.sock"#startup functionfunction_start_mysql(){if [ ! -e "$mysql_sock" ];thenprintf "Starting MySQL...\n"${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null &elseprintf "MySQL is running...\n"exitfi}#stop functionfunction_stop_mysql(){if [ ! -e "$mysql_sock" ];thenprintf "MySQL is stopped...\n"exitelseprintf "Stoping MySQL...\n"${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql3307.sock shutdownfi}#restart functionfunction_restart_mysql(){printf "Restarting MySQL...\n"function_stop_mysqlsleep 2function_start_mysql}case $1 instart)function_start_mysql;;stop)function_stop_mysql;;restart)function_restart_mysql;;*)printf "Usage: /data/${port}/mysql {start|stop|restart}\n"esac

MySQL 5.6 Version Binary package multi-instance installation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.