主頁 > 知識(shí)庫 > Docker實(shí)現(xiàn)Mariadb分庫分表及讀寫分離功能

Docker實(shí)現(xiàn)Mariadb分庫分表及讀寫分離功能

熱門標(biāo)簽:賀州市地圖標(biāo)注app 智能電話機(jī)器人線路 東莞人工智能電銷機(jī)器人供應(yīng)商 長(zhǎng)沙開福怎么申請(qǐng)400電話 百度地圖標(biāo)注要不要錢 江蘇電銷外呼防封系統(tǒng)是什么 金融行業(yè)外呼線路 高德地圖標(biāo)注無營(yíng)業(yè)執(zhí)照 廣州電銷機(jī)器人系統(tǒng)圖

一、簡(jiǎn)介

本文使用docker實(shí)現(xiàn)mysql主從配置,讀寫分離、分庫分表等功能。

二、環(huán)境準(zhǔn)備

1.基礎(chǔ)環(huán)境

java

java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

docker

Client:
 Version:	18.03.0-ce
 API version:	1.37
 Go version:	go1.9.4
 Git commit:	0520e24
 Built:	Wed Mar 21 23:09:15 2018
 OS/Arch:	linux/amd64
 Experimental:	false
 Orchestrator:	swarm

Server:
 Engine:
 Version:	18.03.0-ce
 API version:	1.37 (minimum version 1.12)
 Go version:	go1.9.4
 Git commit:	0520e24
 Built:	Wed Mar 21 23:13:03 2018
 OS/Arch:	linux/amd64
 Experimental:	false

三、安裝Mysql主從配置

1.部署信息

節(jié)點(diǎn)名稱 數(shù)據(jù)名稱 節(jié)點(diǎn)IP 端口
master marster 192.168.92.50 3306
slave slave 192.168.92.51 3307
mycat mycat 192.168.92.50 8066/9066

2.主節(jié)點(diǎn)配置文件

創(chuàng)建mysql主節(jié)點(diǎn)配置文件

mkdir /usr/local/mysql/master
mkdir conf data

創(chuàng)建主節(jié)點(diǎn)配置文件docker.cnf

[mysqld]
server-id=1
log-bin=master-bin #只是讀寫,就只要主庫配置即可.如果要做主從切換,那么主庫和從庫都需要開啟.
skip-host-cache
skip-name-resolve
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
[mysql] 
default-character-set=utf8
[client] 
default-character-set=utf8

創(chuàng)建從節(jié)點(diǎn)配置文件 docker.conf

mkdir /usr/local/mysql/slave
mkdir conf data
[mysqld]
server-id=2
log-bin=master-bin 
skip-host-cache
skip-name-resolve
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
[mysql] 
default-character-set=utf8
[client] 
default-character-set=utf8

3.創(chuàng)建mysql容器

此處使用mariadb最新穩(wěn)定鏡像創(chuàng)建容器

創(chuàng)建主節(jié)點(diǎn)myslq

docker run --name master -p 3306:3306 -v /usr/local/mysql/master/conf:/etc/mysql/conf.d -v /usr/local/mysql/master/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -idt mariadb:latest --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

創(chuàng)建從節(jié)點(diǎn)mysql

docker run --name slave -p 3307:3306 -v /usr/local/mysql/slave/conf:/etc/mysql/conf.d -v /usr/local/mysql/slave/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -idt mariadb:latest --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

4.開啟主從復(fù)制

step 1 進(jìn)入主節(jié)點(diǎn)

docker exec -it master /bin/bash
mysql -uroot -p

step 2 創(chuàng)建用戶

create user 'backUser'@'%' identified by 'root';

grant replication slave on *.* to 'backUser'@'%';

flush privileges;

show master status;
MariaDB [(none)]> show master status;
+-------------------+----------+--------------+------------------+
| File    | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000003 |  787 |    |     |
+-------------------+----------+--------------+------------------+
1 row in set (0.000 sec)

step 3 進(jìn)入從節(jié)點(diǎn)創(chuàng)建用戶開啟同步

docker exec -it slave /bin/bash

mysql -uroot -proot

change master to master_host='192.168.92.51',master_port=3306,master_user='backUser',master_password='root',master_log_file='master-bin.000003',master_log_pos=787;

開啟主從復(fù)制:

start slave;

從節(jié)點(diǎn)設(shè)置日志和文件名要跟主節(jié)點(diǎn)信息對(duì)應(yīng),包括日志記錄起始位置position

檢查主從復(fù)制是否OK

show slave status \G;
*************************** 1. row ***************************
    Slave_IO_State: Waiting for master to send event
     Master_Host: 192.168.92.50
     Master_User: backUser
     Master_Port: 3306
     Connect_Retry: 60
    Master_Log_File: master-bin.000005
   Read_Master_Log_Pos: 343
    Relay_Log_File: mysqld-relay-bin.000002
     Relay_Log_Pos: 556
   Relay_Master_Log_File: master-bin.000005
    Slave_IO_Running: Yes
    Slave_SQL_Running: Yes

Slave出現(xiàn)2個(gè)YES,代表主從復(fù)制設(shè)置成功。

5、安裝Mycat

下載mycat在50節(jié)點(diǎn)實(shí)現(xiàn)安裝

tar -zxvf Mycat-server-1.6.7.1-release-20190213150257-linux.tar.gz

mv mycat/ /usr/local/

修改mycat目錄下 conf的server.xml 文件,指定用戶名和密碼

<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License"); 
	- you may not use this file except in compliance with the License. - You 
	may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 
	- - Unless required by applicable law or agreed to in writing, software - 
	distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
	License for the specific language governing permissions and - limitations 
	under the License. -->
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
	<system>
	<property name="nonePasswordLogin">0</property> <!-- 0為需要密碼登陸、1為不需要密碼登陸 ,默認(rèn)為0,設(shè)置為1則需要指定默認(rèn)賬戶-->
	<property name="useHandshakeV10">1</property>
	<property name="useSqlStat">0</property> <!-- 1為開啟實(shí)時(shí)統(tǒng)計(jì)、0為關(guān)閉 -->
	<property name="useGlobleTableCheck">0</property> <!-- 1為開啟全加班一致性檢測(cè)、0為關(guān)閉 -->
	<property name="sequnceHandlerType">0</property>
	<property name="subqueryRelationshipCheck">false</property>
	<property name="processorBufferPoolType">0</property>
	<property name="handleDistributedTransactions">0</property>
	<property name="useOffHeapForMerge">1</property>
		<!--單位為m-->
  <property name="memoryPageSize">64k</property>
		<!--單位為k-->
		<property name="spillsFileBufferSize">1k</property>
		<property name="useStreamOutput">0</property>
		<!--單位為m-->
		<property name="systemReserveMemorySize">384m</property>
		<!--是否采用zookeeper協(xié)調(diào)切換 -->
		<property name="useZKSwitch">false</property>
		<!-- XA Recovery Log日志名稱 -->
		<!--<property name="XARecoveryLogBaseName">tmlog</property>-->
		<!--如果為 true的話 嚴(yán)格遵守隔離級(jí)別,不會(huì)在僅僅只有select語句的時(shí)候在事務(wù)中切換連接-->
		<property name="strictTxIsolation">false</property>
		<property name="useZKSwitch">true</property>
	</system>
	<user name="root">
		<property name="password">123456</property>
		<property name="schemas">test</property>
	</user>
</mycat:server>

上述配置,指定以root為用戶名,密碼為123456,訪問虛擬邏輯數(shù)據(jù)庫test。

配置rule規(guī)則

修改mycat conf 文件夾下的schema.xml 配置數(shù)據(jù)庫對(duì)應(yīng)規(guī)則

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">

	<schema name="test" checkSQLschema="false" sqlMaxLimit="100">
   <table name="tb_user" primaryKey="id" autoIncrement="true" dataNode="dn1,dn2,dn3,dn4" rule="userrule" />
		<table name="tb_category" primaryKey="id" dataNode="dn1,dn2,dn3,dn4" rule="categoryrule" />
	</schema>
	<dataNode name="dn1" dataHost="localhost1" database="db1" />
	<dataNode name="dn2" dataHost="localhost1" database="db2" />
	<dataNode name="dn3" dataHost="localhost1" database="db3" />
	<dataNode name="dn4" dataHost="localhost1" database="db4" />

	<dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"
			 writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<!-- 讀寫分離配置 -->
		<writeHost host="hostM1" url="192.168.92.50:3306" user="root"
				 password="123456">
			<readHost host="hostS2" url="192.168.92.51:3307" user="root" password="123456" />
		</writeHost>
	</dataHost>
</mycat:schema>

上述配置scheam name 對(duì)應(yīng)server配置文件的虛擬數(shù)據(jù)庫,指定了2個(gè)表信息,tb_user 表主鍵實(shí)現(xiàn)自增長(zhǎng),有4個(gè)數(shù)據(jù)庫節(jié)點(diǎn),使用userrule表規(guī)則。

dataNode 指定了真實(shí)對(duì)應(yīng)的物理數(shù)據(jù)庫節(jié)點(diǎn),對(duì)應(yīng)dataHost說明了讀寫指定的用戶和節(jié)點(diǎn)信息。

配置表分片規(guī)則文件rule.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License"); 
	- you may not use this file except in compliance with the License. - You 
	may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 
	- - Unless required by applicable law or agreed to in writing, software - 
	distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
	License for the specific language governing permissions and - limitations 
	under the License. -->
<!DOCTYPE mycat:rule SYSTEM "rule.dtd">
<mycat:rule xmlns:mycat="http://io.mycat/">
 <!-- 配置數(shù)據(jù)庫規(guī)則 -->
 	<tableRule name="userrule">
		<rule>
			<columns>id</columns>
			<algorithm>func1</algorithm>
		</rule>
	</tableRule>
	<!-- 配置數(shù)據(jù)庫test tb_category規(guī)則 -->
	<tableRule name="categoryrule">
		<rule>
			<columns>id</columns>
			<algorithm>jump-consistent-hash</algorithm>
		</rule>
	</tableRule>
	<function name="murmur"
		class="io.mycat.route.function.PartitionByMurmurHash">
		<property name="seed">0</property><!-- 默認(rèn)是0 -->
		<property name="count">2</property><!-- 要分片的數(shù)據(jù)庫節(jié)點(diǎn)數(shù)量,必須指定,否則沒法分片 -->
		<property name="virtualBucketTimes">160</property><!-- 一個(gè)實(shí)際的數(shù)據(jù)庫節(jié)點(diǎn)被映射為這么多虛擬節(jié)點(diǎn),默認(rèn)是160倍,也就是虛擬節(jié)點(diǎn)數(shù)是物理節(jié)點(diǎn)數(shù)的160倍 -->
		<!-- <property name="weightMapFile">weightMapFile</property> 節(jié)點(diǎn)的權(quán)重,沒有指定權(quán)重的節(jié)點(diǎn)默認(rèn)是1。以properties文件的格式填寫,以從0開始到count-1的整數(shù)值也就是節(jié)點(diǎn)索引為key,以節(jié)點(diǎn)權(quán)重值為值。所有權(quán)重值必須是正整數(shù),否則以1代替 -->
		<!-- <property name="bucketMapPath">/etc/mycat/bucketMapPath</property> 
			用于測(cè)試時(shí)觀察各物理節(jié)點(diǎn)與虛擬節(jié)點(diǎn)的分布情況,如果指定了這個(gè)屬性,會(huì)把虛擬節(jié)點(diǎn)的murmur hash值與物理節(jié)點(diǎn)的映射按行輸出到這個(gè)文件,沒有默認(rèn)值,如果不指定,就不會(huì)輸出任何東西 -->
	</function>

	<function name="crc32slot"
			 class="io.mycat.route.function.PartitionByCRC32PreSlot">
	</function>
	<function name="hash-int"
		class="io.mycat.route.function.PartitionByFileMap">
		<property name="mapFile">partition-hash-int.txt</property>
	</function>
	<function name="rang-long"
		class="io.mycat.route.function.AutoPartitionByLong">
		<property name="mapFile">autopartition-long.txt</property>
	</function>
	<function name="mod-long" class="io.mycat.route.function.PartitionByMod">
		<!-- how many data nodes -->
		<property name="count">3</property>
	</function>

	<function name="func1" class="io.mycat.route.function.PartitionByLong">
		<property name="partitionCount">8</property>
		<property name="partitionLength">128</property>
	</function>
	<function name="latestMonth"
		class="io.mycat.route.function.LatestMonthPartion">
		<property name="splitOneDay">24</property>
	</function>
	<function name="partbymonth"
		class="io.mycat.route.function.PartitionByMonth">
		<property name="dateFormat">yyyy-MM-dd</property>
		<property name="sBeginDate">2015-01-01</property>
	</function>
	
	<function name="rang-mod" class="io.mycat.route.function.PartitionByRangeMod">
  	<property name="mapFile">partition-range-mod.txt</property>
	</function>
	
	<function name="jump-consistent-hash" class="io.mycat.route.function.PartitionByJumpConsistentHash">
		<property name="totalBuckets">3</property>
	</function>
</mycat:rule>

上述文件重點(diǎn)關(guān)注第一個(gè)tableRule、rule指定了分片規(guī)則在哪個(gè)表字段,algorithm指定了分片的算法,其中  func1 與文件后面function名稱為func1對(duì)應(yīng),此處使用了PartitionByLong分片算法。

conf下增加sequence_conf.properties文件,其內(nèi)容如下:

TB_USER.HISIDS=
TB_USER.MINID=1
TB_USER.MAXID=20000
TB_USER.CURID=1

主要申明了主鍵增長(zhǎng)的策略。

四、Mycat分庫分表實(shí)踐測(cè)試

1.master節(jié)點(diǎn)手動(dòng)創(chuàng)建數(shù)據(jù)庫

master節(jié)點(diǎn)手動(dòng)創(chuàng)建4個(gè)數(shù)據(jù)庫db1,db2,db3,db4 (不要操作從節(jié)點(diǎn))

此時(shí)打開slave節(jié)點(diǎn),會(huì)觀察到slave也會(huì)自動(dòng)創(chuàng)建4個(gè)數(shù)據(jù)庫。

2.開啟mycat

使用命令 ./mycat start 開啟mycat

./mycat start 啟動(dòng)
./mycat stop 停止 
./mycat console 前臺(tái)運(yùn)行 
./mycat restart 重啟服務(wù)
./mycat pause 暫停 
./mycat status 查看啟動(dòng)狀態(tài)

如果啟動(dòng)失敗,請(qǐng)查看 /usr/local/mycat的wrapper.log 日志文件信息。

FATAL | wrapper | 2019/04/21 14:36:09 | ERROR: Could not write pid file /usr/local/mycat/logs/mycat.pid: No such file or directory

如果遇到上述錯(cuò)誤,請(qǐng)?jiān)趍ycat 目錄創(chuàng)建logs 文件夾,重新啟動(dòng)即可。

[root@localhost mycat]# bin/mycat status
Mycat-server is running (5065).

上述消息則表示mycat啟動(dòng)成功。

2.放行mycat通信端口

firewall-cmd --zone=public --add-port=8066/tcp --permanent
firewall-cmd --zone=public --add-port=9066/tcp --permanent
firewall-cmd --reload

使用docker鏡像開啟mycat容器實(shí)例

docker run --name mycat -v /usr/local/mycat/conf/schema.xml:/usr/local/mycat/conf/schema.xml -v /usr/local/mycat/conf/rule.xml:/usr/local/mycat/conf/rule.xml -v /usr/local/mycat/conf/server.xml:/usr/local/mycat/conf/server.xml -v /usr/local/mycat/conf/sequence_conf.properties:/usr/local/mycat/conf/sequence_conf.properties --privileged=true -p 8066:8066 -p 9066:9066 -e MYSQL_ROOT_PASSWORD=123456 -d longhronshens/mycat-docker 

或者關(guān)閉防火墻。

3. mycat連接

使用navicate連接mycat,端口8066(9066為管理端口)

使用命令連接mycat

[root@localhost ~]# mysql -h127.0.0.1 -uroot -p123456 -P8066 
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.6.29-mycat-1.6.7.1-release-20190213150257 MyCat Server (OpenCloudDB)

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> 

管理端命令:

mysql -h127.0.0.1 -uroot -proot -P9066 

查看虛擬邏輯庫:

MySQL [(none)]> show databases;
+----------+
| DATABASE |
+----------+
| test   |
+----------+
1 row in set (0.00 sec)

MySQL [(none)]> 

使用邏輯庫創(chuàng)建表:

MySQL [(none)]> use test;

CREATE TABLE `tb_user` (
 `id` bigint(20) NOT NULL AUTO_INCREMENT,
 `username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用戶名',
 `password` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密碼,加密存儲(chǔ)',
 `phone` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '注冊(cè)手機(jī)號(hào)',
 `email` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '注冊(cè)郵箱',
 `created` datetime(0) NOT NULL,
 `updated` datetime(0) NOT NULL,
 PRIMARY KEY (`id`) USING BTREE,
 UNIQUE INDEX `username`(`username`) USING BTREE,
 UNIQUE INDEX `phone`(`phone`) USING BTREE,
 UNIQUE INDEX `email`(`email`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 54 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '用戶表' ROW_FORMAT = Compact;

可以看到mycat,mysql主從都創(chuàng)建了該表

在創(chuàng)建一張表:

CREATE TABLE `tb_category` (
 `id` varchar(5) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
 `name` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '名字',
 `sort_order` int(4) NOT NULL DEFAULT 1 COMMENT '排列序號(hào),表示同級(jí)類目的展現(xiàn)次序,如數(shù)值相等則按名稱次序排列。取值范圍:大于零的整數(shù)',
 `created` datetime(0) NULL DEFAULT NULL,
 `updated` datetime(0) NULL DEFAULT NULL,
 PRIMARY KEY (`id`) USING BTREE,
 INDEX `updated`(`updated`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;

插入一條數(shù)據(jù):

INSERT INTO `tb_user`(id,username,password,phone,email,created,updated) VALUES (7, 'zhangsan', 'e10adc3949ba59abbe56e057f20f883e', '13488888888', 'aa@a', '2015-04-06 17:03:55', '2015-04-06 17:03:55');

為測(cè)試分庫效果,我們插入不同ID的數(shù)據(jù)來觀察一下:

INSERT INTO `tb_user`(id,username,password,phone,email,created,updated) VALUES (128, 'zhang02', 'e10adc3949ba59abbe56e057f20f88ss', '13488888882', 'aa@01.com', '2015-04-06 17:03:57', '2015-04-06 17:04:55');

INSERT INTO `tb_user`(id,username,password,phone,email,created,updated) VALUES (256, 'zhang03', 'e10adc3949ba59abbe56e057f20f88ss', '13488888883', 'aa@02.com', '2015-04-06 17:03:57', '2015-04-06 17:04:55');

INSERT INTO `tb_user`(id,username,password,phone,email,created,updated) VALUES (384, 'zhang05', 'e10adc3949ba59abbe56e057f20f88ss', '13488888885', 'aa@05.com', '2015-04-06 17:03:57', '2015-04-06 17:04:55');

可以看到數(shù)據(jù)分別分布在db1/db2/db3/db4,分布的規(guī)則取決于插入數(shù)據(jù)的主鍵在rule.xml 設(shè)置的分片規(guī)則約束。

查看mycat節(jié)點(diǎn)健康狀態(tài),在主節(jié)點(diǎn)輸入如下命令:

[root@localhost ~]# mysql -h127.0.0.1 -uroot -p123456 -P9066 
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.6.29-mycat-1.6.7.1-release-20190213150257 MyCat Server (monitor)

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> show @@heartbeat;
+--------+-------+---------------+------+---------+-------+--------+---------+--------------+---------------------+-------+
| NAME  | TYPE | HOST     | PORT | RS_CODE | RETRY | STATUS | TIMEOUT | EXECUTE_TIME | LAST_ACTIVE_TIME  | STOP |
+--------+-------+---------------+------+---------+-------+--------+---------+--------------+---------------------+-------+
| hostM1 | mysql | 192.168.92.50 | 3306 |    1 |   0 | idle  |  30000 | 1,9,6    | 2019-04-21 20:44:40 | false |
| hostS2 | mysql | 192.168.92.51 | 3307 |    1 |   0 | idle  |  30000 | 1,9,67381  | 2019-04-21 20:44:40 | false |
+--------+-------+---------------+------+---------+-------+--------+---------+--------------+---------------------+-------+
2 rows in set (0.36 sec)

上述 RS_CODE 1代表節(jié)點(diǎn)正常,-1代表節(jié)點(diǎn)異常。

查詢mycat所有命令:

MySQL [(none)]> show @@help;
+--------------------------------------------------------------+--------------------------------------------+
| STATEMENT                          | DESCRIPTION                |
+--------------------------------------------------------------+--------------------------------------------+
| show @@time.current                     | Report current timestamp          |
| show @@time.startup                     | Report startup timestamp          |
| show @@version                        | Report Mycat Server version        |
| show @@server                        | Report server status            |
| show @@threadpool                      | Report threadPool status          |
| show @@database                       | Report databases              |
| show @@datanode                       | Report dataNodes              |
| show @@datanode where schema = ?               | Report dataNodes              |
| show @@datasource                      | Report dataSources             |
| show @@datasource where dataNode = ?             | Report dataSources             |
| show @@datasource.synstatus                 | Report datasource data synchronous     |
| show @@datasource.syndetail where name=?           | Report datasource data synchronous detail |
| show @@datasource.cluster                  | Report datasource galary cluster variables |
| show @@processor                       | Report processor status          |
| show @@command                        | Report commands status           |
| show @@connection                      | Report connection status          |
| show @@cache                         | Report system cache usage         |
| show @@backend                        | Report backend connection status      |
| show @@session                        | Report front session details        |
| show @@connection.sql                    | Report connection sql           |
| show @@sql.execute                      | Report execute status           |
| show @@sql.detail where id = ?                | Report execute detail status        |
| show @@sql                          | Report SQL list              |
| show @@sql.high                       | Report Hight Frequency SQL         |
| show @@sql.slow                       | Report slow SQL              |
| show @@sql.resultset                     | Report BIG RESULTSET SQL          |
| show @@sql.sum                        | Report User RW Stat            |
| show @@sql.sum.user                     | Report User RW Stat            |
| show @@sql.sum.table                     | Report Table RW Stat           |
| show @@parser                        | Report parser status            |
| show @@router                        | Report router status            |
| show @@heartbeat                       | Report heartbeat status          |
| show @@heartbeat.detail where name=?             | Report heartbeat current detail      |
| show @@slow where schema = ?                 | Report schema slow sql           |
| show @@slow where datanode = ?                | Report datanode slow sql          |
| show @@sysparam                       | Report system param            |
| show @@syslog limit=?                    | Report system mycat.log          |
| show @@white                         | show mycat white host           |
| show @@white.set=?,?                     | set mycat white host,[ip,user]       |
| show @@directmemory=1 or 2                  | show mycat direct memory usage       |
| show @@check_global -SCHEMA= ? -TABLE=? -retry=? -interval=? | check mycat global table consistency    |
| switch @@datasource name:index                | Switch dataSource             |
| kill @@connection id1,id2,...                | Kill the specified connections       |
| stop @@heartbeat name:time                  | Pause dataNode heartbeat          |
| reload @@config                       | Reload basic config from file       |
| reload @@config_all                     | Reload all config from file        |
| reload @@route                        | Reload route config from file       |
| reload @@user                        | Reload user config from file        |
| reload @@sqlslow=                      | Set Slow SQL Time(ms)           |
| reload @@user_stat                      | Reset show @@sql @@sql.sum @@sql.slow   |
| rollback @@config                      | Rollback all config from memory      |
| rollback @@route                       | Rollback route config from memory     |
| rollback @@user                       | Rollback user config from memory      |
| reload @@sqlstat=open                    | Open real-time sql stat analyzer      |
| reload @@sqlstat=close                    | Close real-time sql stat analyzer     |
| offline                           | Change MyCat status to OFF         |
| online                            | Change MyCat status to ON         |
| clear @@slow where schema = ?                | Clear slow sql by schema          |
| clear @@slow where datanode = ?               | Clear slow sql by datanode         |
+--------------------------------------------------------------+--------------------------------------------+
59 rows in set (0.16 sec)

遇到如下錯(cuò)誤:

修改schema.xml 文件屬性checkSQLschema:

<schema name="test" checkSQLschema="true" sqlMaxLimit="100">

遇到如下錯(cuò)誤:

jvm 1  | Caused by: io.mycat.config.util.ConfigException: org.xml.sax.SAXParseException; lineNumber: 97; columnNumber: 42; Attribute "defaultAccount" must be declared for element type "user".
jvm 1  | 	at io.mycat.config.loader.xml.XMLServerLoader.load(XMLServerLoader.java:111)
jvm 1  | 	at io.mycat.config.loader.xml.XMLServerLoader.<init>(XMLServerLoader.java:69)
jvm 1  | 	at io.mycat.config.loader.xml.XMLConfigLoader.<init>(XMLConfigLoader.java:56)
jvm 1  | 	at io.mycat.config.ConfigInitializer.<init>(ConfigInitializer.java:77)
jvm 1  | 	at io.mycat.config.MycatConfig.<init>(MycatConfig.java:72)
jvm 1  | 	at io.mycat.MycatServer.<init>(MycatServer.java:144)
jvm 1  | 	at io.mycat.MycatServer.<clinit>(MycatServer.java:96)
jvm 1  | 	... 7 more
jvm 1  | Caused by: org.xml.sax.SAXParseException; lineNumber: 97; columnNumber: 42; Attribute "defaultAccount" must be declared for element type "user".

請(qǐng)修改server.xml 文件,將user模塊的defaultAccount取消:

<user name="root" >
	<property name="password">123456</property>
	<property name="schemas">test</property>
</user>

最后放一張mycat查詢結(jié)果截圖:

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。

標(biāo)簽:滄州 永州 張家界 洛陽 松原 廊坊 北京 玉樹

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Docker實(shí)現(xiàn)Mariadb分庫分表及讀寫分離功能》,本文關(guān)鍵詞  Docker,實(shí)現(xiàn),Mariadb,分庫,分表,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Docker實(shí)現(xiàn)Mariadb分庫分表及讀寫分離功能》相關(guān)的同類信息!
  • 本頁收集關(guān)于Docker實(shí)現(xiàn)Mariadb分庫分表及讀寫分離功能的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章

    上一篇:詳解使用VMware安裝Permeate靶場(chǎng)系統(tǒng)實(shí)踐

    下一篇:Windows與Linux之間文件傳輸?shù)姆椒▓D解