mysql 多实例部署

使用多个配置文件启动不同的进程来实现多实例,这种方式的优势逻辑简单,配置简单,缺点是管理起来不太方便。

使用多个配置文件启动多个不同进程的情况:

环境介绍:

mysql 版本:5.6.20

操作系统:centos

mysql实例数:2个

实例占用端口分别为:3306、3307

操作用户:root 

编译安装mysql

tar xzvf mysql.tar.gz

cd mysql

初始化数据库

/opt/app/mysql/bin/mysql_install_db --basedir=/opt/app/mysql --datadir=/dbdata_3306 

/opt/app/mysql/bin/mysql_install_db --basedir=/opt/app/mysql --datadir=/dbdata_3307 

创建配置文件

vim /dbdata_3306/my.cnf

3306的配置文件如下:

[mysqld]

character_set_client=utf8

character-set-server=utf8

socket=/opt/app/mysql/data_3306/mysql.sock

basedir=/opt/app/mysql

datadir=/opt/app/mysql/data_3306

user=mysql

port=3306

skip_name_resolve=1

innodb_force_recovery = 0 

# --------------- #

# Slowlog Options #

# --------------- #

slow-query-log=1

slow-query-log-file=/var/log/mysql/query_slow.log


# --------------- #

# MyISAM Options  #

# --------------- #

key_buffer_size=64M    #64M

query_cache_size=256M

table_open_cache=512        #1024

sort_buffer_size=6M     #4M

thread_cache_size=64


# --------------- #

# InnoDB Options  #

# --------------- #

innodb_buffer_pool_size=1024M

innodb_file_per_table 

innodb_lock_wait_timeout=60

innodb_rollback_on_timeout=1

innodb_log_file_size=100M

innodb_log_buffer_size=2M       #4M

innodb_flush_log_at_trx_commit=2

innodb_thread_concurrency=48    #8

innodb_flush_method=O_DIRECT



# ------------------ #

# performance tuning #

# ------------------ #

max_connections=16384 

max_connect_errors=1844674407370954751

connect_timeout=20

table_open_cache=5120   #2726

read_rnd_buffer_size=16M

back_log=512  #384

max_allowed_packet=64M  #32M

thread_stack=256K

read_buffer_size=8M

join_buffer_size=16M

myisam_sort_buffer_size=128M

tmp_table_size=512M #512M

max_heap_table_size=1024M #512M

thread_concurrency=4   #16cores logic CPU*2

#binlog_cache_size=4M

query_cache_limit=32M

wait_timeout=43200

interactive_timeout=43200


# -------------- #

# binlog options #

# -------------- #

server_id=103

binlog_cache_size = 1M

max_binlog_cache_size = 512M

max_binlog_size = 512M

log-bin = binlog

binlog_format = mixed

expire_logs_days = 1


[mysqld_safe]

log-error=/var/log/mysqld_3306.log

pid-file=/var/log/mysql/mysqld_3306.pid


vim /dbdata_3307/my.cnf

3307的配置文件如下:(同3306将3306端口修改成33077)

启动mysql:

/opt/app/mysql/bin/mysqld --defaults-file=/opt/app/mysql/data_3306/my.cnf &

/opt/app/mysql/bin/mysqld --defaults-file=/opt/app/mysql/data_3307/my.cnf &

添加权限:

/opt/app/mysql/bin/mysql -uroot -proot -S /opt/app/mysql/dbdata_3306/mysql.sock

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' identified by 'root' with grant option; 

flush privileges;

/opt/app/mysql/bin/mysql -uroot -proot -S /opt/app/mysql/dbdata_3307/mysql.sock

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' identified by 'root' with grant option; 

flush privileges;



你可能感兴趣的:(mysql 多实例部署)