mysql多实例安装
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql多实例安装相关的知识,希望对你有一定的参考价值。
mysql多实例安装
一台服务器上安装多个mysql实例
充分利用硬件资源
通过 mysqld_multi 实现
(1)停掉之前的单实例数据库
mysqladmin -uroot -p shutdown
第一步不用管
(2)建多实例相关数据目录
mkdir -p /data1
mkdir -p /data2
mkdir -p /data3
mkdir -p /data4
chown -R mysql.mysql /data1
chown -R mysql.mysql /data2
chown -R mysql.mysql /data3
chown -R mysql.mysql /data4
(3)初始化各个实例(mysql5.6x版本)
scripts/mysql_install_db --user=mysql --datadir=/data1
scripts/mysql_install_db --user=mysql --datadir=/data2
scripts/mysql_install_db --user=mysql --datadir=/data3
scripts/mysql_install_db --user=mysql --datadir=/data4
cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multid
chkconfig mysqld_multid on
(4)通过 mysqld_multi 相关命令查看及启动
[[email protected] mysql]# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is not running
MySQL server from group: mysqld2 is not running
MySQL server from group: mysqld3 is not running
MySQL server from group: mysqld3 is not running
分别启动mysql实例1234
[[email protected] mysql]# mysqld_multi start 1
[[email protected] mysql]# mysqld_multi start 2
[[email protected] mysql]# mysqld_multi start 3
[[email protected] mysql]# mysqld_multi start 4
或者[[email protected] mysql]# mysqld_multi start
[[email protected] mysql]# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
MySQL server from group: mysqld3 is running
MySQL server from group: mysqld4 is running
[[email protected] mysql]# netstat -anlp | grep mysql
tcp 0 0 :::3307 :::* LISTEN 29467/mysqld
tcp 0 0 :::3308 :::* LISTEN 29469/mysqld
tcp 0 0 :::3309 :::* LISTEN 29474/mysqld
tcp 0 0 :::3310 :::* LISTEN 25447/mysqld
unix 2 [ ACC ] STREAM LISTENING 35931 25447/mysqld /tmp/mysql.sock4
unix 2 [ ACC ] STREAM LISTENING 38712 29467/mysqld /tmp/mysql.sock1
unix 2 [ ACC ] STREAM LISTENING 38703 29469/mysqld /tmp/mysql.sock2
unix 2 [ ACC ] STREAM LISTENING 38724 29474/mysqld /tmp/mysql.sock3
分别进入实例
mysql -uroot -p -S /tmp/mysql.sock1
mysql -uroot -p -S /tmp/mysql.sock2
mysql -uroot -p -S /tmp/mysql.sock3
mysql -uroot -p -S /tmp/mysql.sock4
(5)Federated测试
3307准备相关数据
mysql> show variables like ‘%port%‘;
+---------------------+-------+
| Variable_name | Value |
+---------------------+-------+
| innodb_support_xa | ON |
| large_files_support | ON |
| port | 3307 |
| report_host | |
| report_password | |
| report_port | 3307 |
| report_user | |
+---------------------+-------+
7 rows in set (0.00 sec)
mysql> create database burn;
Query OK, 1 row affected (5.01 sec)
mysql> use burn;
Database changed
mysql>
mysql> create table book(id int not null auto_increment,name varchar(10) not null,primary key(id));
Query OK, 0 rows affected (0.04 sec)
mysql> insert into book values(1,"english");
Query OK, 1 row affected (0.06 sec)
mysql> select * from book;
+----+---------+
| id | name |
+----+---------+
| 1 | english |
+----+---------+
1 row in set (0.00 sec)
mysql> create user ‘burn‘@‘127.0.0.1‘ identified by ‘123‘;
Query OK, 0 rows affected (0.11 sec)
mysql> grant select on burn.* to ‘burn‘@‘127.0.0.1‘;
Query OK, 0 rows affected (0.03 sec)
mysql> show grants for ‘burn‘@‘127.0.0.1‘;
+-------------------------------------------------------------------------------------------------------------+
| Grants for [email protected] |
+-------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO ‘burn‘@‘127.0.0.1‘ IDENTIFIED BY PASSWORD ‘*23AE809DDACAF96AF0FD78ED04B6A265E05AA257‘ |
| GRANT SELECT ON `burn`.* TO ‘burn‘@‘127.0.0.1‘ |
+-------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
3308测试Federated测试
mysql> show variables like ‘%port%‘;
+---------------------+-------+
| Variable_name | Value |
+---------------------+-------+
| innodb_support_xa | ON |
| large_files_support | ON |
| port | 3308 |
| report_host | |
| report_password | |
| report_port | 3308 |
| report_user | |
+---------------------+-------+
7 rows in set (0.00 sec)
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)
没有打开FEDERATED功能
在/etc/my.cnf中添加
[mysqld2]
federated
mysqld_multi stop 2
mysqld_multi start 2
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| FEDERATED | YES | Federated MySQL storage engine | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| PERFORMANCE_SCHEMA | YES | Performance Schema
表示已经打开
最后测试
mysql> create database federated_test;
Query OK, 1 row affected (5.01 sec)
mysql> use federated_test;
Database changed
mysql> create table feterated_book(
-> id int not null auto_increment,
-> name varchar(10) not null,primary key(id)
-> )engine=federated
-> connection=‘mysql://burn:[email protected]:3307/burn/book‘;
Query OK, 0 rows affected (0.11 sec)
mysql> select * from feterated_book;
+----+---------+
| id | name |
+----+---------+
| 1 | english |
+----+---------+
1 row in set (0.00 sec)
搞定!!!!!!
附件多实例配置文件
[mysqld]
federated
########basic settings########
server-id = 11
port = 3306
user = mysql
bind_address = 10.166.224.32
#autocommit = 0
character_set_server=utf8mb4
skip_name_resolve = 1
max_connections = 800
max_connect_errors = 1000
datadir = /data/mysql_data
#datadir = /usr/local/mysql-5.6.27-linux-glibc2.5-x86_64/data
transaction_isolation = READ-COMMITTED
explicit_defaults_for_timestamp = 1
join_buffer_size = 134217728
tmp_table_size = 67108864
tmpdir = /tmp
max_allowed_packet = 16777216
sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"
interactive_timeout = 1800
wait_timeout = 1800
read_buffer_size = 16777216
read_rnd_buffer_size = 33554432
sort_buffer_size = 33554432
########log settings########
log_error = error.log
slow_query_log = 1
slow_query_log_file = slow.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_throttle_queries_not_using_indexes = 10
expire_logs_days = 90
long_query_time = 2
min_examined_row_limit = 100
########replication settings########
master_info_repository = TABLE
relay_log_info_repository = TABLE
#log_bin = bin.log
sync_binlog = 1
#gtid_mode = on
#enforce_gtid_consistency = 1
#log_slave_updates
binlog_format = row
relay_log = relay.log
relay_log_recovery = 1
binlog_gtid_simple_recovery = 1
slave_skip_errors = ddl_exist_errors
########innodb settings########
innodb_page_size = 8192
innodb_buffer_pool_size = 2G
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 2000
innodb_lock_wait_timeout = 5
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
#innodb_log_group_home_dir = /redolog/
#innodb_undo_directory = /undolog/
innodb_undo_logs = 128
innodb_undo_tablespaces = 3
innodb_flush_neighbors = 1
innodb_log_file_size = 128M
innodb_log_buffer_size = 16777216
innodb_purge_threads = 1
innodb_large_prefix = 1
innodb_thread_concurrency = 64
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_sort_buffer_size = 67108864
########semi sync replication settings########
plugin_dir=/usr/local/mysql/lib/plugin
plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
loose_rpl_semi_sync_master_enabled = 1
loose_rpl_semi_sync_slave_enabled = 1
loose_rpl_semi_sync_master_timeout = 5000
[mysqld-5.7]
innodb_buffer_pool_dump_pct = 40
innodb_page_cleaners = 4
innodb_purge_threads = 4
innodb_undo_log_truncate = 1
innodb_max_undo_log_size = 2G
innodb_purge_rseg_truncate_frequency = 128
binlog_gtid_simple_recovery=1
log_timestamps=system
transaction_write_set_extraction=MURMUR32
#binlog_checksum=NONE # only for group replication
#group replication setting
#plugin_load=group_replication.so
#loose_group_replication_group_name=e5720089-6b00-11e5-b248-fa163e30f9a2
#loose_group_replication_start_on_boot=1
#loose_group_replication_recovery_user=‘rpl_user‘
#loose_group_replication_recovery_password=‘rpl_pass‘
show_compatibility_56=on
[mysqld_multi]
mysqld = mysqld_safe
log=/usr/local/mysql/mysql_multi.log
[mysqld1]
server-id=111
basedir=/usr/local/mysql
datadir=/data1
port=3307
socket=/tmp/mysql.sock1
[mysqld2]
server-id=222
basedir=/usr/local/mysql
datadir=/data2
port=3308
socket=/tmp/mysql.sock2
[mysqld3]
server-id=333
basedir=/usr/local/mysql56
datadir=/data3
port=3309
socket=/tmp/mysql.sock3
以上是关于mysql多实例安装的主要内容,如果未能解决你的问题,请参考以下文章