Home  >  Article  >  Database  >  MySQL 使用mysqld_multi部署单机多实例详细过程

MySQL 使用mysqld_multi部署单机多实例详细过程

WBOY
WBOYOriginal
2016-06-07 16:00:48988browse

随着硬件层面的发展,Linux系统多核已经是普通趋势,而MySQL是单进程多线程,所以先天上对多进程的利用不是很高,虽然5.6版本已经

随着硬件层面的发展,Linux系统多核已经是普通趋势,而MySQL是单进程多线程,所以先天上对多进程的利用不是很高,虽然5.6版本已经在这方面改进很多,但是也没有达到100%,所以为了充分的利用系统资源,MySQL有自己的补充,那就是可以部署多实例,一个实例一个端口。

1,准备好mysql环境

源码安装mysql参考与源码包下载地址:

1.1,准备好安装环境

        groupaddmysql
useradd-g mysql mysql
autoreconf--force --install
libtoolize--automake --force
automake--force --add-missing
yuminstall -y libtoolize
yuminstall cmake -y
yuminstall gcc gcc-c++ -y
yuminstall -y ncurses-devel.x86_64
yuminstall -y cmake.x86_64
yuminstall -y libaio.x86_64
yuminstall -y bison.x86_64
yuminstall -y gcc-c++.x86_64
yuminstall make -y 

1.2,创建mysql编译根目录

        mkdir-p /usr/local/mysql

1.3,解压缩源码包

          tar -xvf mysql-5.6.12.tar.gz

          cd mysql-5.6.12

1.4,编译安装

        timecmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DMYSQL_DATADIR=/home/data/mysql/data -DWITH_INNOBASE_STORAGE_ENGINE=1-DMYSQL_UNIX_ADDR==/usr/local/mysql/mysql.sock -DMYSQL_USER=mysql-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

        由于time make耗时比较长,所以事先已经安装好

        timemake

        timemake install 

2,准备第一个实例3307 

2.1建立好目录

mkdir /usr/local/mysql3307
chown -R mysql.mysql /usr/local/mysql3307/
mkdir -p /home/data/mysql3307/data
chown -R mysql.mysql /home/data/mysql3307
chown -R mysql.mysql/home/data/mysql3307/data
mkdir -p /home/data/mysql3307/binlog
chown -R mysql.mysql /home/data/mysql3307
mkdir -p /home/data/mysql3307/relay_log/
chown -R mysql.mysql /home/data/mysql3307/ 

2.2 配置文件

[mysqld_multi]

mysqld = /usr/local/mysql/bin/mysqld_safe

mysqladmin =/usr/local/mysql/bin/mysqladmin

log =/home/mysql/mydata/log/mysqld_multi.log

[mysqld1]

socket = /usr/local/mysql3307/mysql.sock
port = 3307
pid-file = /usr/local/mysql3307/mysqld.pid
datadir = /home/data/mysql3307/data
log_bin=/home/data/mysql3307/binlog
server-id = 1230
relay_log =/home/data/mysql3307/relay_log/mysql-relay-bin
log_slave_updates = 1
read_only = 0
innodb_buffer_pool_size = 128M
innodb_flush_log_at_trx_commit = 0

2.3 初始化数据库

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

3,准备第二个实例3308

3.1 建立好目录

mkdir /usr/local/mysql3308
chown -R mysql.mysql /usr/local/mysql3308/
mkdir -p /home/data/mysql3308/data
chown -R mysql.mysql /home/data/mysql3308
chown -R mysql.mysql/home/data/mysql3308/data
mkdir -p /home/data/mysql3308/binlog
chown -R mysql.mysql /home/data/mysql3308
mkdir -p /home/data/mysql3308/relay_log/
chown -R mysql.mysql /home/data/mysql3308/

3.2 配置文件

[mysqld2]

socket = /usr/local/mysql3308/mysql.sock

port = 3308

pid-file = /usr/local/mysql3308/mysqld.pid

datadir = /home/data/mysql3308/data

 

log_bin=/home/data/mysql3308/binlog

server-id = 2230

relay_log =/home/data/mysql3308/relay_log/mysql-relay-bin

log_slave_updates = 1

read_only = 0

 

innodb_buffer_pool_size = 128M

innodb_flush_log_at_trx_commit = 0

3.3 初始化数据库

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

4,准备第三个实例3309

4.1 建立好目录

mkdir /usr/local/mysql3309
chown -R mysql.mysql /usr/local/mysql3309/
mkdir -p /home/data/mysql3309/data
chown -R mysql.mysql /home/data/mysql3309
chown -R mysql.mysql/home/data/mysql3309/data
mkdir -p /home/data/mysql3309/binlog
chown -R mysql.mysql /home/data/mysql3309
mkdir -p /home/data/mysql3309/relay_log/
chown -R mysql.mysql /home/data/mysql3309/ 

4.2 配置文件

[mysqld3]

socket = /usr/local/mysql3309/mysql.sock

port = 3309

pid-file = /usr/local/mysql3309/mysqld.pid

datadir = /home/data/mysql3309/data

 

log_bin=/home/data/mysql3309/binlog

server-id = 3230

relay_log = /home/data/mysql3309/relay_log/mysql-relay-bin

log_slave_updates = 1

read_only = 0

 

innodb_buffer_pool_size = 128M

innodb_flush_log_at_trx_commit = 0

4.3 初始化数据库

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

初始化信息如下所示:

  [mysql@data02 ~]$ /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql3309/data
WARNING: Could not write to config file /usr/local/mysql/my-new.cnf: 权限不够
 
Installing MySQL system tables...2015-05-14 09:31:20 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-05-14 09:31:20 12307 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)
 
2015-05-14 09:31:20 12307 [Warning] Buffered warning: Changed limits: table_cache: 431 (requested 2000)
 
2015-05-14 09:31:20 12307 [Note] InnoDB: The InnoDB memory heap is disabled
2015-05-14 09:31:20 12307 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-05-14 09:31:20 12307 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-05-14 09:31:20 12307 [Note] InnoDB: Using CPU crc32 instructions
2015-05-14 09:31:20 12307 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-05-14 09:31:20 12307 [Note] InnoDB: Completed initialization of buffer pool
2015-05-14 09:31:20 12307 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2015-05-14 09:31:20 12307 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2015-05-14 09:31:20 12307 [Note] InnoDB: Database physically writes the file full: wait...
2015-05-14 09:31:20 12307 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2015-05-14 09:31:20 12307 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2015-05-14 09:31:21 12307 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2015-05-14 09:31:21 12307 [Warning] InnoDB: New log files created, LSN=45781
2015-05-14 09:31:21 12307 [Note] InnoDB: Doublewrite buffer not found: creating new
2015-05-14 09:31:21 12307 [Note] InnoDB: Doublewrite buffer created
2015-05-14 09:31:21 12307 [Note] InnoDB: 128 rollback segment(s) are active.
2015-05-14 09:31:21 12307 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-05-14 09:31:21 12307 [Note] InnoDB: Foreign key constraint system tables created
2015-05-14 09:31:21 12307 [Note] InnoDB: Creating tablespace and datafile system tables.
2015-05-14 09:31:21 12307 [Note] InnoDB: Tablespace and datafile system tables created.
2015-05-14 09:31:21 12307 [Note] InnoDB: Waiting for purge to start
2015-05-14 09:31:21 12307 [Note] InnoDB: 5.6.12 started; log sequence number 0
2015-05-14 09:31:21 12307 [Note] Binlog end
2015-05-14 09:31:21 12307 [Note] InnoDB: FTS optimize thread exiting.
2015-05-14 09:31:21 12307 [Note] InnoDB: Starting shutdown...
2015-05-14 09:31:22 12307 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
 
Filling help tables...2015-05-14 09:31:22 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-05-14 09:31:22 12332 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)
 
2015-05-14 09:31:22 12332 [Warning] Buffered warning: Changed limits: table_cache: 431 (requested 2000)
 
2015-05-14 09:31:22 12332 [Note] InnoDB: The InnoDB memory heap is disabled
2015-05-14 09:31:22 12332 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-05-14 09:31:22 12332 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-05-14 09:31:22 12332 [Note] InnoDB: Using CPU crc32 instructions
2015-05-14 09:31:22 12332 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-05-14 09:31:22 12332 [Note] InnoDB: Completed initialization of buffer pool
2015-05-14 09:31:22 12332 [Note] InnoDB: Highest supported file format is Barracuda.
2015-05-14 09:31:22 12332 [Note] InnoDB: 128 rollback segment(s) are active.
2015-05-14 09:31:22 12332 [Note] InnoDB: Waiting for purge to start
2015-05-14 09:31:22 12332 [Note] InnoDB: 5.6.12 started; log sequence number 1625977
2015-05-14 09:31:22 12332 [Note] Binlog end
2015-05-14 09:31:22 12332 [Note] InnoDB: FTS optimize thread exiting.
2015-05-14 09:31:22 12332 [Note] InnoDB: Starting shutdown...
2015-05-14 09:31:24 12332 [Note] InnoDB: Shutdown completed; log sequence number 1625987
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:
 
  /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
  /usr/local/mysql/bin/mysqladmin -u root -h data02 password 'new-password'
 
Alternatively you can run:
 
  /usr/local/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 . ; /usr/local/mysql/bin/mysqld_safe &
 
You can test the MySQL daemon with mysql-test-run.pl
 
  cd mysql-test ; perl mysql-test-run.pl
 
Please report any problems with the ./bin/mysqlbug script!
 
The latest information about MySQL is available on the web at
 
 
 
Support MySQL by buying support/licenses at
 
WARNING: Could not copy config file template /usr/local/mysql/support-files/my-default.cnf to
/usr/local/mysql/my-new.cnf, may not have access rights to do so.
You may want to copy the file manually, or create your own,
it will then be used by default by the server when you start it.
 
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

5,,启动多实例数据库

mkdir -p /home/mysql/data/log

[mysql@data02 data]$ mysqld_multi--defaults-extra-file=/etc/my.cnf start 1,2,3

[mysql@data02 data]$

后台日志信息:

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn