MySQL 5.6版本二進制包多實例安裝
阿新 • • 發佈:2018-01-09
ren tcp 安裝 starting func function defaults ogr socket 一、環境介紹
(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
MySQL 5.6版本二進制包多實例安裝