02.mysql多实例安装实战

2.1 什么是mysql多实例?

简单的说,mysql 多实例就是在一台服务器上同时开启多个不同的服务端口(如 3306、 3307),同时运行多个 mysql 服务进程,这些服务进程通过不同的 socket 监听不同的服务端 口来提供服务 这些 mysql 多实例公用一套 mysql 安装程序,使用不同的 my.cnf(也可以相同)配置 文件、启动程序(也可以相同)和数据文件,在提供服务时,多实例 mysql 在逻辑上看来是各自独立的,他们根据配置文件的对应设定值,获得服务器相应数量的硬件资源。

2.2 mysql多实例结构图

2.3 安装mysql多实例

2.3.1 实战安装 mysql 多实例需要的依赖包

[[email protected] ~]# yum install ncurses-devel libaio-devel –y
[[email protected] ~]# rpm -qa ncurses-devel libaio-devel libaio-devel-0.3.107-10.el6.x86_64 ncurses-devel-5.7-4.20090207.el6.x86_64?

2.3.2  安装编译 mysql 需要的软件

[[email protected] tools]# pwd /home/tools
[[email protected] tools]# ls cmake-2.8.8.tar.zip
[[email protected] tools]# unzip cmake-2.8.8.tar.zip Archive: cmake-2.8.8.tar.zip inflating: cmake-2.8.8.tar.gz
[[email protected] tools]# ls cmake-2.8.8.tar.gz cmake-2.8.8.tar.zip
[[email protected] tools]# tar xfv cmake-2.8.8.tar.gz
[[email protected] tools]# ls cmake-2.8.8 cmake-2.8.8.tar.gz cmake-2.8.8.tar.zip
[[email protected] tools]# cd cmake-2.8.8
[[email protected] cmake-2.8.8]# ./configure
[[email protected] cmake-2.8.8]# gmake
[[email protected] cmake-2.8.8]# gmake install

关于 cmake 软件也可以直接 yum 安装

yum install -y cmake

2.3.3 安装 mysql 软件

1、创建安装 mysql 软件的用户 mysql
[[email protected] ~]# useradd mysql -s /sbin/nologin –M
2、解压 mysql-5.5.27 的软件包
[[email protected] tools]# ls
cmake-2.8.8 cmake-2.8.8.tar.gz cmake-2.8.8.tar.zip mysql-5.5.27 mysql-5.5.27.tar.gz
3、编译安装 mysql(下面是编译参数)
/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.27     -DMYSQL_DATADIR=/application/mysql-5.5.27/data     -DMYSQL_UNIX_ADDR=/application/mysql-5.5.27/tmp/mysql.sock     -DDEFAULT_CHARSET=utf8     -DDEFAULT_COLLATION=utf8_general_ci     -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii     -DENABLED_LOCAL_INFILE=ON     -DWITH_INNOBASE_STORAGE_ENGINE=1     -DWITH_FEDERATED_STORAGE_ENGINE=1     -DWITH_BLACKHOLE_STORAGE_ENGINE=1     -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1     -DWITHOUT_PARTITION_STORAGE_ENGINE=1     -DWITH_FAST_MUTEXES=1     -DWITH_ZLIB=bundled     -DENABLED_LOCAL_INFILE=1     -DWITH_READLINE=1     -DWITH_EMBEDDED_SERVER=1     -DWITH_DEBUG=0
[[email protected] mysql-5.5.27]# make && make install
[[email protected] mysql-5.5.27]# ln -s /application/mysql-5.5.27 /application/mysql
[[email protected] ~]# echo "PATH=/application/mysql/bin:$PATH" >>/etc/profile 把 mysql 的命令放
入至全局环境变量之中
[[email protected] ~]# . /etc/profile
[[email protected] mysql-5.5.27]# cd /application/mysql
[[email protected] mysql]# ls
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files

2.3.4  创建存放两个 mysql 实例的数据目录

[[email protected] ~]# mkdir /mysqldata/{3306,3307}/data -p
[[email protected] ~]# tree /mysqldata
/mysqldata
├── 3306
    │ └── data
└── 3307
    └── data 4 directories, 0 files?

2.3.5 创建两个 mysql 多实例的配置文件

2.3.5.1  3306 的实例

#实例1:3306配置文件
[[email protected] 3306]# ls
data my.cnf(配置文件) mysql(程序启动文件) mysql-bin.000001 mysql-bin.index
mysqld.pid mysql_oldboy3306.err mysql.sock
[[email protected] 3306]# cat my.cnf
[client]
port = 3306
socket = /mysqldata/3306/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = mysql
port = 3306
socket = /mysqldata/3306/mysql.sock
basedir = /application/mysql
datadir = /mysqldata/3306/data
open_files_limit = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_cache = 614
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
#default_table_type = InnoDB
thread_stack = 192K
#transaction_isolation = READ-COMMITTED
tmp_table_size = 2M
max_heap_table_size = 2M?
long_query_time = 1
#log_long_format
#log-error = /data/3306/error.log
#log-slow-queries = /data/3306/slow.log
pid-file = /mysqldata/3306/mysql.pid
log-bin = /mysqldata/3306/mysql-bin
relay-log = /mysqldata/3306/relay-bin
relay-log-info-file = /mysqldata/3306/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
#myisam_sort_buffer_size = 1M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam_recover
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db=mysql
server-id = 1
innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 2M
[mysqld_safe]
log-error=/mysqldata/3306/mysql_oldboy3306.err
pid-file=/mysqldata/3306/mysqld.pid

实例 1、3306 的启动文件,并授权执行的权限
[[email protected] 3306]# chmod +x /mysqldata/3306/mysql
[[email protected] 3306]# cat mysql
#!/bin/sh
################################################
#this scripts is created by oldboy at 2007-06-09
################################################
#init
port=3306
mysql_user="root"
mysql_pwd="oldboy"
CmdPath="/application/mysql/bin"
mysql_sock="/mysqldata/${port}/mysql.sock"
#startup function
function_start_mysql()
{
 if [ ! -e "$mysql_sock" ];then
 printf "Starting MySQL...\n"
 /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/mysqldata/${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
/mysqldata/${port}/mysql.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: /mysqldata/${port}/mysql {start|stop|restart}\n"
esac

更改 3306 实例目录的属主和属组权限,初始化数据库
[[email protected] 3306]# chown -R mysql.mysql /mysqldata/3306
[[email protected] mysql]# ./scripts/mysql_install_db --datadir=/mysqldata/3306/data --
basedir=/application/mysql --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/application/mysql/bin/mysqladmin -u root password ‘new-password‘
/application/mysql/bin/mysqladmin -u root -h mysql password ‘new-password‘
Alternatively you can run:
/application/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test

databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /application/mysql ; /application/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /application/mysql/scripts/mysqlbug script!

启动 3306 实例
[[email protected] 3306]# /mysqldata/3306/mysql start
[[email protected] 3306]# lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 31375 mysql 12u IPv4 98252 0t0 TCP *:mysql (LISTEN)

2.3.5.2  3307 的实例

3307 实例配置文件
[[email protected] 3307]# ls
data my.cnf(配置文件) mysql(程序启动文件) mysqld.pid mysql_oldboy3307.err
mysql.sock
[[email protected] 3307]# cat my.cnf
[client]
port = 3307
socket = /mysqldata/3307/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = mysql
port = 3307
socket = /mysqldata/3307/mysql.sock
basedir = /application/mysql
datadir = /mysqldata/3307/data
open_files_limit = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_cache = 614
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M

join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
#default_table_type = InnoDB
thread_stack = 192K
#transaction_isolation = READ-COMMITTED
tmp_table_size = 2M
max_heap_table_size = 2M
#long_query_time = 1
#log_long_format
#log-error = /data/3307/error.log
#log-slow-queries = /data/3307/slow.log
pid-file = /mysqldata/3307/mysql.pid
#log-bin = /data/3307/mysql-bin
relay-log = /mysqldata/3307/relay-bin
relay-log-info-file = /mysqldata/3307/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
#myisam_sort_buffer_size = 1M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam_recover
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db=mysql
server-id = 3
innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads = 4

innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 2M
`
[mysqld_safe]
log-error=/mysqldata/3307/mysql_oldboy3307.err
pid-file=/mysqldata/3307/mysqld.pid

3307 实例的启动配置文件
[[email protected] 3307]# cat /mysqldata/3307/mysql
#!/bin/sh
################################################
#this scripts is created by oldboy at 2007-06-09
#oldboy QQ:31333741
#site:http://www.etiantian.org
#blog:http://oldboy.blog.51cto.com
#oldboy trainning QQ group: 208160987 226199307 44246017
################################################
#init
port=3307
mysql_user="root"
mysql_pwd="oldboy"
CmdPath="/application/mysql/bin"
mysql_sock="/mysqldata/${port}/mysql.sock"
#startup function
function_start_mysql()
{
 if [ ! -e "$mysql_sock" ];then
 printf "Starting MySQL...\n"
 /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/mysqldata/${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
/mysqldata/${port}/mysql.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: /mysqldata/${port}/mysql {start|stop|restart}\n"
esac

更改 3307 实例的目录权限,初始化数据库
[[email protected] 3307]# chown -R mysql.root /mysqldata/3307
[[email protected] mysql]# ./scripts/mysql_install_db --datadir=/mysqldata/3307/data --
basedir=/application/mysql --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/application/mysql/bin/mysqladmin -u root password ‘new-password‘
/application/mysql/bin/mysqladmin -u root -h mysql password ‘new-password‘
Alternatively you can run:
/application/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /application/mysql ; /application/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /application/mysql/scripts/mysqlbug script!
启动 3307 实例
[[email protected] mysql]# /mysqldata/3307/mysql start
Starting MySQL...
[[email protected] mysql]# lsof -i :3307
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 32195 mysql 11u IPv4 99276 0t0 TCP *:opsession-prxy (LISTEN)

2.3.6 多实例通过本地登录

多实例本地登录一般是通过 socket 文件来指定具体到那个实例的,此文件的具体位置是在 mysql 编译过程或者 my.cnf 文件里指定的,在本地登录数据库时,登录程序会通过socket 文件来判断登录的是哪个数据库实例例如:通过 mysql –uroot –ppcwangjixuan –S /mysqldata/3307/mysql.sock 可知,登录的是 3307 这个实例,mysql.sock 文件是 mysql 服务端与本地 mysql 客户端进行通信的 unix 套接字文件。

2.3.7  远程连接登录 mysql 多实例

远程登录 mysql 多实例中的一个实例中,通过 TCP 端口(port)来指定所要登录的mysql 实例,此端口的配置是在 mysql 配置文件 my.cnf 中指定的例如:在 mysql –oldboy –ppcwangjixuan –h 10.0.0.171 –P 3307 中,-P 为端口参数,后面接具体的实例端口,端口是一种逻辑连接位置,是客户端程序被分派到计算机上特殊服务程序的一种方式,强调提前在 10.0.0.171 上对 oldboy 用户做了授权。

原文地址:https://www.cnblogs.com/hackerlin/p/12537222.html

时间: 2024-10-04 11:19:27

02.mysql多实例安装实战的相关文章

linux下mysql多实例安装(转)

转自:http://www.cnblogs.com/xuchenliang/p/6843990.html 1.MySQL多实例介绍 1.1.什么是MySQL多实例 MySQL多实例就是在一台机器上开启多个不同的服务端口(如:3306,3307),运行多个MySQL服务进程,通过不同的socket监听不同的服务端口来提供各自的服务:: 1.2.MySQL多实例的特点有以下几点 1:有效利用服务器资源,当单个服务器资源有剩余时,可以充分利用剩余的资源提供更多的服务. 2:节约服务器资源 3:资源互相

MySQL多实例安装配置

MySQL多实例安装配置 一.基本概念 MySQL多实例就是,在一台机器上开启多个不同的服务端口(如:3306,3307,3308...),运行多个MySQL服务进程,这些服务进程通过不同的socket监听不同的端口提供服务. MySQL可以共用一套安全程序,使用不同的my.cnf配置文件,启动程序,数据文件. 逻辑上是独立的,但是一个实例过载过高的时候会对其他造成影响. MySQL多实例的作用与问题: 1.有效利用服务器资源 2.节约服务器资源 3.资源互相抢占问题 当某个服务实现并发生很高的

Windows下MySQL多实例安装/主从复制/重置密码

Windows创建MySQL多实例 安装MYSQL和实例1 运行mysql-installer-community-5.7.16.0.msi 选择组件 MySQL Server 5.7.16 – X64 MySQL Utilities 1.6.4 – X64 MySQL Workbench 6.3.7 – X64 执行安装 配置端口3306 Windows Service Name设置为MYSQL 复制实例 将C:\ProgramData\MySQL\MySQL拷贝为MYSQL1和MYSQL2文

MySQL多实例安装

    MySQL数据库(一) 作者:Jack 归档:学习笔记 2017/6/19 目  录 MySQl数据库(一)... 3 第1章概述:... 4 1.1 MySQL介绍:... 4 1.2 MariaDB数据库的诞生背景介绍... 4 1.3 MySQL多实例介绍... 5 1.3.1 什么是MySQL多实例... 5 1.3.2 MySQL多实例的作用与问题... 6 1.4 MySQL多实例的生产应用场景... 7 第2章关系型数据库与非关系型数据库... 8 2.1 关系型数据库..

03 :mysql模型 和 mysql多实例安装

MySQL 简单知识-------------------------------------------------------------------------------------------------------------- 一.mysql是C/S模型结构,即:client (客户端)+ server(服务器)  二.应用程序如何连接到mysql: 1.TCP/IP 方式连接数据库mysql -uadmin -p123 -h 10.0.0.51 -P 3306 可以证明:(1)数

MySQL多实例安装注意

MySQL多实例编译安装注意 # wget -c http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.26.tar.gz # cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_USER=mysql # make && make install 每个实例里的用户是独立的,当配置完/etc/my.cnf之后启动所有实例mysqld_multi start .然后分别加-S选项sock

mysql单实例安装配置指南

1.操作系统:CentOS 2.数据库: mysql-5.1.73.tar.gz 3.任务:单实例安装配置指南 提示:下载数据库有两种方式:一种是官网,另一种途径是国内镜象网站:国内镜象下载资源的速度比官网要快,例如,我们这次下载的就是国内搜狐镜象: http://mirrors.sohu.com/mysql/MySQL-5.1/ http://mirrors.sohu.com/ 整个安装过程: [[email protected] tools]#wget http://mirrors.sohu

centos下mysql多实例安装3306、3307实例(2014-10-15)

背景说明 mysql的安装方法有多种,如二进制安装.源码编译安装.yum安装等.yum安装只能安装mysql 5.1 版本:源码安装编译的过程比较长,若没有对源码进行修改且要求使用mysql较高版本,建议使用二进制安装.本文以二进制安装mysql,且使用mysqld_mutil进行mysql多实例管理. 是否安装了mysql 首先查看下服务器中是否有安装mysql,若端口被占用,则需要选择其他端口. 下载mysql cd /usr/src wget http://cdn.mysql.com/Do

Mysql多实例 安装以及配置

MySQL多实例 1.什么是MySQL多实例 简单地说,Mysql多实例就是在一台服务器上同时开启多个不同的服务端口(3306.3307),同时运行多个Mysql服务进程,这些服务进程通过不同的socket监听不同的服务端口来提供服务. 这些Mysql多实例公用一套Mysql安装程序,使用不同的my.cnf(也可以相同)配置文件,启动程序(也可以相同)和数据文件.在提供服务时,多实例 Mysql在逻辑上看来是各自独立的,它们根据配置文件的对应设定值,获得服务器相应数量的硬件资源. 打个比方,My