一、MySQL多实例介绍
mysql多实例,共用一套mysql安装程序,使用不同的配置文件(my.cnf)、启动程序、和数据文件,即在一台服务器上同时开启多个不同的服务器端口(3306,3307),同时运行多个mysql服务进程,这些服务进程通过不同的socket监听不同的服务器端口来提供服务。
二、安装mysql多实例
1.下载mysql/cmake安装包
1 2 3 |
|
2.建立账号
1 2 3 4 5 6 |
|
3.配置安装环境
创建目录并授权
1 2 3 4 |
|
安装依赖
1 |
|
配置解析
1 2 3 4 |
|
4.安装mysql(在这一步和之前,安装配置都和单实例配置相同)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
1 2 |
|
5.创建mysql多实例配置文件
1 2 |
|
MySQL 3306实例 |
MySQL 3307实例 |
[client] port = 3306 socket = /db/3306/mysql.sock [mysql] no-auto-rehash [mysqld] user = mysql port = 3306 socket = /db/3306/mysql.sock basedir = /usr/local/mysql/ datadir = /db/3306/data open_files_limit = 1024 back_log = 600 max_connections = 800 max_connect_errors = 3000 table_cache = 1024 external-locking = FALSE max_allowed_packet = 16M sort_buffer_size = 8M join_buffer_size = 8M thread_cache_size = 100 thread_concurrency = 8 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 pid-file=/db/3306/mysql.pid relay-log = /db/3306/relay-bin relay-log-info-file = /db/3306/relay-log.info binlog_cache_size = 1M max_binlog_cache_size = 1M max_binlog_size = 1M key_buffer_size = 16M read_buffer_size = 1M read_rnd_buffer_size = 1M bulk_insert_buffer_size = 1M 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:28M:autoextend innodb_file_io_threads = 4 innodb_thread_concurrency = 16 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 8M 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=/db/3306/mysql_3306.err pid-file=/db/3306/mysql.pid |
[client] port = 3307 socket = /db/3307/mysql.sock [mysql] no-auto-rehash [mysqld] user = mysql port = 3307 socket = /db/3307/mysql.sock basedir = /usr/local/mysql/ datadir = /db/3307/data open_files_limit = 1024 back_log = 600 max_connections = 800 max_connect_errors = 3000 table_cache = 1024 external-locking = FALSE max_allowed_packet = 16M sort_buffer_size = 8M join_buffer_size = 8M thread_cache_size = 100 thread_concurrency = 8 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 pid-file=/db/3307/mysql.pid relay-log = /db/3307/relay-bin relay-log-info-file = /db/3307/relay-log.info binlog_cache_size = 1M max_binlog_cache_size = 1M max_binlog_size = 1M key_buffer_size = 16M read_buffer_size = 1M read_rnd_buffer_size = 1M bulk_insert_buffer_size = 1M 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:28M:autoextend innodb_file_io_threads = 4 innodb_thread_concurrency = 16 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 8M 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=/db/3307/mysql_3307.err pid-file=/db/3307/mysql.pid |
完成后,/db目录结构:
1 2 3 4 5 6 7 8 |
|
6.创建mysql多实例启动文件(3307实例只需更改端口即可)
1 2 |
|
编写MySQL启动程序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
给程序加权限
1 2 3 |
|
最终/db目录结构:
1 2 3 4 5 6 7 8 9 10 |
|
7.配置mysql环境变量
1 2 |
|
8.初始化mysql多实例数据库文件
1 2 3 |
|
9.启动多实例mysql
1 2 3 4 |
|
10.为mysql多实例设置密码(安装好之后,默认没有密码)
1 2 |
|
11.登录mysql
1 2 |
|
12.权限设定(因为启动程序中带有mysql密码)
1 2 |
|