# yum install ncurses-devel -y
# yum install libaio-devel -y
注意:参考“mysql二进制包安装”这一章节
请查考MySQL系列之B------MySQL安装准备、MySQL系列之B------MySQL安装
# groupadd mysql
# useradd -s /sbin/nologin -g mysql -Mmysql
#注意:useradd命令参数简要说明
#1、-s /sbin/nologin 表示禁止该用户登录,加强安全
#2、-g 指定属于mysql组
#3、-M表示不创建用户家目录
# mkdir -p /data/{3307,3308}/data
目录解析:
/data 实例的总目录
/data/3307 3307实例的目录
/data/3308 3308实例的目录
/data/3307/data 3307实例的数据目录
/data/3308/data 3308实例的数据目录
注意:生产硬件配置:MEM 32g、双CPU8core、硬盘6*600g sas 15k/rpm 2-3个实例
# cd /mysql/mysql
# scripts/mysql_install_db--basedir=/mysql --datadir=/data/3307/data --user=mysql
# scripts/mysql_install_db--basedir=/mysql --datadir=/data/3308/data --user=mysql
1、3307配置文件/data/3307/
[client]
port=3307
socket=/data/3307/mysql.sock
prompt=\\u@hostname \\r:\\m:\\s->
[mysqld]
basedir =/mysql
datadir =/data/3307/data
port =3307
server_id =2
socket =/data/3307/mysql.sock
log-bin=/data/3307/mysql_bin
binlog_format=mixed
#binlog-do-db=
#binlog-ignore-db=
long_query_time=1
relay-log=/data/3307/relay_bin
relay-log-info-file=/data/3307/relay_log.info
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/data/3307/mysql_err.log
pid-file=/data/3307/mysql_pid.pid
2、3308配置文件/data/3308/
[client]
port=3308
socket=/data/3308/mysql.sock
prompt=\\u@hostname \\r:\\m:\\s->
[mysqld]
basedir =/mysql
datadir =/data/3308/data
port =3308
server_id =3
socket =/data/3308/mysql.sock
log-bin=/data/3308/mysql_bin
binlog_format=mixed
#binlog-do-db=
#binlog-ignore-db=
long_query_time=1
relay-log=/data/3308/relay_bin
relay-log-info-file=/data/3308/relay_log.info
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/data/3308/mysql_err.log
pid-file=/data/3308/mysql_pid.pid
#!/bin/bash
############################################################
#this scripts is created by liuweixinat 2015-06-18
#liuweixin QQ:1433203077
############################################################
#init
port=3307
mysql_user="root"
mysql_pwd="oracle"
CmdPath="/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 function()
function_stop_mysql()
{
if[ ! -e "$mysql_sock" ];then
printf"Stoping MySQL...\n"
exit
else
printf "Stoping Mysql...\n"
${CmdPath}/mysqladmin-u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
fi
}
#restart function
function_restart_mysql()
{
printf"Restarting MySQL...\n"
function_stop_mysql
sleep2
function_start_mysql
}
#function_kill_mysql()
#{
# kill-9 $(ps -ef | grep ‘bin/mysqld_safe‘ | grep ${mysql_port} | awk ‘{printf $2}‘)
# kill-9 $(ps -ef | grep ‘libexec/mysqld‘ | grep ${mysql_port} | awk ‘{printf $2}‘)
#}
case $1 in
start)
function_start_mysql;;
stop)
function_stop_mysql;;
#kill)
# function_kill_mysql;;
restart)
function_restart_mysql;;
*)
printf"Usage:/data/${port}/mysql {start|stop|restart}\n"
esac
#!/bin/bash
############################################################
#this scripts is created by liuweixinat 2015-06-18
#liuweixin QQ:1433203077
############################################################
#init
port=3308
mysql_user="root"
mysql_pwd="oracle"
CmdPath="/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 function()
function_stop_mysql()
{
if[ ! -e "$mysql_sock" ];then
printf"Stoping MySQL...\n"
exit
else
printf "Stoping Mysql...\n"
${CmdPath}/mysqladmin-u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
fi
}
#restart function
function_restart_mysql()
{
printf"Restarting MySQL...\n"
function_stop_mysql
sleep2
function_start_mysql
}
#function_kill_mysql()
#{
# kill-9 $(ps -ef | grep ‘bin/mysqld_safe‘ | grep ${mysql_port} | awk ‘{printf $2}‘)
# kill-9 $(ps -ef | grep ‘libexec/mysqld‘ | grep ${mysql_port} | awk ‘{printf $2}‘)
#}
case $1 in
start)
function_start_mysql;;
stop)
function_stop_mysql;;
#kill)
# function_kill_mysql;;
restart)
function_restart_mysql;;
*)
printf"Usage:/data/${port}/mysql {start|stop|restart}\n"
esac
[root@mysql03 mysql]# /data/3307/mysql start
Starting MySQL...
[root@mysql03 mysql]# /data/3308/mysql start
Starting MySQL...
[root@mysql03 mysql]# netstat -lnt 330
Active Internet connections (onlyservers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 :::3307 :::* LISTEN
tcp 0 0 :::3308 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:25 :::* LISTEN
登录有两种方法:
mysql -uroot -p -S/data/3307/mysql.sock
mysql -h127.0.0.1 -uroot -p --port=330X
注意:如果指定socket文件,则不需要-h127.0.0.1或者-h localhost,同时,也不需要指定--port=330X端口号
本文出自 “技术博” 博客,谢绝转载!
原文地址:http://hostman.blog.51cto.com/6303208/1673497