配置MySQL資料庫多執行個體

來源:互聯網
上載者:User

標籤:mysql 多執行個體 主從複製

一、什麼是mysql多執行個體

    簡單的說就是在一台機器上開啟多個不同的服務連接埠(例如:3306、3307),運行多個mysql服務進程,這些服務進程通過不同的socket監聽不同的服務連接埠來提供各自的服務。

    這些mysql多執行個體共用一套mysql安裝程式,使用不同(也可以相同)的my.cnf設定檔、啟動程式、資料檔案。在提供服務時,多執行個體mysql在邏輯上看來是各自獨立的,多個執行個體是根據設定檔中配置的參數來擷取伺服器相關硬體資源。

二、mysql常見應用情境

    由於公司業務訪問量不是很大,伺服器的資源基本都是浪費的,這時候很適合使用多執行個體的應用,如果對SQL語句最佳化做的比較好,mysql多執行個體是一個很值得使用的技術,即使並發很大,合理分配系統資源,也不會有太大問題。

三、mysql多執行個體常見配置方案

3.1 安裝mysql資料庫

 具體安裝方法,請參見 編譯方式安裝MySQL資料庫 。

3.2 配置多執行個體

 3.2.1 建立多執行個體目錄

[[email protected] ~]# mkdir -p /data/{3306,3307}/data[[email protected] ~]# tree /data        /data  ├── 3306        │   └── data        └── 3307     └── data

 3.2.2 將資料目錄及臨時目錄授權mysql使用者(在安裝mysql之前已經建立mysql使用者組和使用者)

[[email protected] ~]# chown -R mysql.mysql /data[[email protected] ~]# chmod -R 1777 /tmp[[email protected] ~]# ls -ld /data/{3306,3307}/data        drwxr-xr-x. 2 mysql mysql 4096 1月  18 22:40 /data/3306/data        drwxr-xr-x. 2 mysql mysql 4096 1月  18 22:40 /data/3307/data

 3.2.3 建立設定檔my.cnf

3306連接埠
3307連接埠

[client]
port            = 3306
socket          = /data/3306/mysql.sock


[mysql]
no-auto-rehash


[mysqld]
user    = mysql
port    = 3306
socket  = /data/3306/mysql.sock
basedir = /application/mysql
datadir = /data/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 = /data/3306/mysql.pid
log-bin = /data/3306/mysql-bin
relay-log = /data/3306/relay-bin
relay-log-info-file = /data/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=/data/3306/err_mysql_3306.err
pid-file=/data/3306/mysqld.pid

[client]
port            = 3307
socket          = /data/3307/mysql.sock

[mysql]
no-auto-rehash


[mysqld]
user    = mysql
port    = 3307
socket  = /data/3307/mysql.sock
basedir = /application/mysql
datadir = /data/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 = /data/3307/mysql.pid
#log-bin = /data/3307/mysql-bin
relay-log = /data/3307/relay-bin
relay-log-info-file = /data/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=/data/3307/err_mysql_3307.err
pid-file=/data/3307/mysqld.pid

                

配置MySQL資料庫多執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.