Binary installation:[[email protected] ~]# mkdir /home/lufeng/tools -p[[email protected] ~]# cd /home/lufeng/tools [[email protected] tools]# rz[[email protected] tools]# tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz[[email protected] tools]# mkdir -p /application/mysql-5.5.49[[email protected] tools]# mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49 create a MySQL user | group [[email protected] tools]# groupadd mysql[[email protected] tools]# useradd mysql -g mysql -s /sbin/nologin -m[[email protected] tools]# ln -s /application/ mysql-5.5.49/ /application/mysql[email protected] mysql]# sed -i ' s#/usr/local/ Mysql#/application/mysql#g ' /application/mysql/bin/mysqld_safe Create multi-instance data file directory [[email protected]_2 ~ ]# mkdir -p /Data/{3306,3307}/data Configure the appropriate configuration file: [[email protected]_2 ~]# cat /data/3306/my.cnf ####### #############################################[client] #password = your_passwordport = 3306socket = /data/3306/mysql.sock[mysqld]user = mysqlport = 3306socket = /data/3306/mysql.sockbasedir = /application/mysqldatadir = /data/3306/ datapid-file = /data/3306/mysql.pidrelay-log =&nbsP;/data/3306/relay-binrelay-log-info-file = /data/3306/relay-log.infoskip-external-lockingkey_buffer _size = 16kmax_allowed_packet = 1mtable_open_cache = 4sort_buffer_size = 64Kread_buffer_size = 256Kread_rnd_buffer_size = 256Knet_buffer_length = 2kthread_stack = 128kserver-id = 1[mysqldump]quickmax_ Allowed_packet = 2m[mysql]no-auto-rehash[mysql_safe]log-error=/data/3306/mysql_ lufeng3306.errpid-file=/data/3306/mysqlf.pid##############################################[[email protected]_2 ~]# cat /data/3307/my.cnf ########################### ##################[client] #password = your_passwordport = 3307socket = /data/3307/mysql.sock[mysqld]user = mysqlport = 3307socket = /data/3307/mysql.sockbasedir = /application/mysqldatadir = /data/3307/datapid-file = /data/3307/ Mysql.pidrelay-log = /data/3307/relay-binrelay-log-info-file = /data/3307/relay-log.infoskip-external-lockingkey_buffer_size = 16kmax_allowed_packet = 1Mtable_open_cache = 4sort_buffer_size = 64Kread_buffer_size = 256kread_rnd_buffer_size = 256knet_buffer_length = 2kthread_stack = 128kserver-id = 2[mysqldump]quickmax_allowed_packet = 2m[mysql]no-auto-rehash[mysql_safe]log-error=/ data/3307/mysql_lufeng3307.errpid-file=/data/3307/mysqlf.pid############################################## Create startup file [[email protected]_2 ~]# cat /data/3306/mysql#!/bin/sh############################## # # #mysql 3306 by lufeng @2017.4.3################################ #intport =3306mysql_user= " Root "mysql_pwd=" 199429 "cmdpath="/application/mysql/bin "mysql_sock="/data/${port}/mysql.sock "#startup Function function_start_mysql () {        IF [ ! -E "$mysql _sock" ];then printf "starting mysql...\n" /bin/sh ${cmdpath}/mysqld_safe --defaults-file=/data/${ Port}/my.cnf 2>&1 >/dev/null & else printf "Mysql is running...\n "  EXIT        FI} #stop functionfunction_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}/mysql.sock shutdown FI} #restart functionfunction_restart_mysql () { printf "Restarting mysql...\n" function_stop_mysql sleep 2 function_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##########################################################[[email protected]_2 ~]# cat /data/3307/mysql#!/bin/sh################################ #mysql 3307 by lufeng @2017.4.3################################ #intport =3307mysql_user= "root" Mysql_pwd= "199429" cmdpath= "/application/mysql/bin" mysql_sock= "/data/${port}/mysql.sock" #startup function function_start_mysql () { if [ ! -e "$ Mysql_sock " ];then printf "starting mysql...\n" /bin/sh ${cmdpath}/mysqld_safe --defaults-file=/data/${port}/ my.cnf 2>&1 >/dev/null & else printf "Mysql is running...\n " exit         FI} #stop functionfunction_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}/mysql.sock shutdown    FI} #resTart functionfunction_restart_mysql () { printf " restarting mysql...\n " function_stop_mysql sleep 2 function_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###################################################### #配置多实例文件权限 [[email protected]_2 ~]# chown -r mysql.mysql /data[[email protected]_2 ~]# find / Data -name mysql|xargs chmod 700[[email protected]_2 ~]# find&nbsP;/DATA -NAME MYSQL -EXEC LS -L {} \; -RWX------ 1 mysql mysql 999 4 Month 3 13:33 /data/3306/mysql-rwx------ 1 mysql mysql 1210 4 month 3 13:35 /data/3307/mysql global variable: [[email protected]_ 2 ~]# ls /application/mysql/bin/mysql/application/mysql/bin/mysql[[email protected]_2 ~]# echo ' Export path=/application/mysql/bin: $PATH ' >>/etc/profile[[email protected]_2 ~]# tail -1 /etc/profileexport path=/application/mysql/bin: $PATH [[ Email protected]_2 ~]# source /etc/profile[[email protected]_2 ~]# echo $PATH/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/ Bin Initialization Database File [[email protected]_2 scripts]# cd /application/mysql/scripts/[[email Protected]_2 scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql[[email protected]_2 scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/ 3307/data --user=mysqlinstalling mysql system tables ... 170403 13:47:58 [note] /application/mysql/bin/mysqld (mysqld 5.5.49) starting  AS PROCESS 2971&NBSP, ..... Okfilling help tables ... 170403 13:47:59 [note] /application/mysql/bin/mysqld (mysqld 5.5.49) starting  AS PROCESS 2980&NBSP, ..... ok============ Success Flag Start command: [[Email protected]_2 ~]# /data/3306/mysql startstarting mysql ..... [[email protected]_2 ~]# /data/3307/mysql startstarting mysql ... [[email protected]_2 ~]# netstat -lntup|grep mysqltcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 3638/mysqld tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 3962/mysqld Configure Boot:[[email protected]_2 ~]# echo "Mysql multi instances" >>/etc/rc.local[[email protected]_2 ~]# echo "/data/3306/mysql start" >>/etc/rc.local &nbSp; [[email protected]_2 ~]# echo "/data/3307/mysql start" >>/etc/rc.local [[email protected] _2 ~]# tail -3 /etc/rc.local mysql multi instances/data/3306/mysql Start/data/3307/mysql start login: [[email protected] ~]# mysql -s /data/3306/ mysql.sock Security Configuration: [[email protected] ~]# mysqladmin -u root -s /data/ 3307/mysql.sock password ' 199429 ' [[email protected] ~]# mysql -s /data/3306 /mysql.sock -uroot -penter password:
This article is from the "Trance" blog, make sure to keep this source http://bestlufeng.blog.51cto.com/11790256/1912675
MySQL database multi-instance configuration