码迷,mamicode.com
首页 > 数据库 > 详细

MySQL多实例安装

时间:2016-06-14 15:43:54      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:

安装MySQL依赖包

yum install -y ncurses-devel libaio-devel


配置不同的my.cnf

改端口和文件路径以及server-id

[client]

port = 3306

socket = /data/3306/mysql.sock

[mysqld]

port = 3306

socket = /data/3306/mysql.sock

basedir = /usr/local/mysql

datadir = /data/3306/data

log-error = /data/3306/error.log

log-slow-queries = /data/3306/slow.log

pid-file = /data/3306/mysql.pid

log-bin = /data/3306/mysql-bin

relay-log = /data/3306/relay-bin

skip-external-locking

key_buffer_size = 16K

max_allowed_packet = 1M

table_open_cache = 4

sort_buffer_size = 64K

read_buffer_size = 256K

read_rnd_buffer_size = 256K

net_buffer_length = 2K

thread_stack = 128K

server-id = 1

[mysqldump]

quick

max_allowed_packet = 16M

[mysql]

no-auto-rehash

[myisamchk]

key_buffer_size = 8M

sort_buffer_size = 8M

[mysqlhotcopy]

interactive-timeout


初始化

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/3306/data --user=mysql

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/3307/data --user=mysql


启动脚本

mysqld_safe --defaults-file=/data/3306/my.cnf 2>&1 >/dev/null &

mysqld_safe --defaults-file=/data/3307/my.cnf 2>&1 >/dev/null &

停止脚本

mysqladmin -u root -p passwd -S /data/3306/mysql.sock shutdown

登录MySQL

mysql -S /data/3306/mysql.sock

system mysql -S /data/3307/mysql.sock


设置密码

mysqladmin -u root -S /data/3306/mysql.sock password ‘password‘





mysqld启动程序


#!/bin/sh


port=3306

mysql_user="root"

mysql_pwd="123qwe"

CmdPath="/usr/local/mysql/bin"

mysql_sock="/data/${port}/mysql.sock"


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 &

fi

}


stop_mysql() {

printf "stoping MySQL...\n"

#/bin/sh ${CmdPath}/

mysqladmin -u${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown

}


restart_mysql() {

printf "Restarting MySQL...\n"

stop_mysql

start_mysql

}


kill_mysql() {

kill -9 $(ps -ef | grep ‘bin/mysqld_safe‘ | grep ${port} | awk ‘{printf $2}‘)

kill -9 $(ps -ef | grep ‘libexec/mysqld‘ | grep ${port} | awk ‘{printf $2}‘)

}


case $1 in

start)

start_mysql;;

stop)

stop_mysql;;

kill)

kill_mysql;;

restart)

restart_mysql;;

*)

echo "Usage: /data/dbdata_${port}/mysqld {start|stop|restart|kill}";;

esac



授权远程连接

GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123qwe‘ WITH GRANT OPTION;

MySQL多实例安装

标签:

原文地址:http://www.cnblogs.com/hygs/p/5583974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!