欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

mycat基礎(chǔ)實(shí)驗(yàn)之主從配置讀寫分離和分表

mycat實(shí)驗(yàn)之主從配置讀寫分離和分表

創(chuàng)新互聯(lián)是一家以網(wǎng)絡(luò)技術(shù)公司,為中小企業(yè)提供網(wǎng)站維護(hù)、成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、網(wǎng)站備案、服務(wù)器租用、空間域名、軟件開發(fā)、微信小程序等企業(yè)互聯(lián)網(wǎng)相關(guān)業(yè)務(wù),是一家有著豐富的互聯(lián)網(wǎng)運(yùn)營推廣經(jīng)驗(yàn)的科技公司,有著多年的網(wǎng)站建站經(jīng)驗(yàn),致力于幫助中小企業(yè)在互聯(lián)網(wǎng)讓打出自已的品牌和口碑,讓企業(yè)在互聯(lián)網(wǎng)上打開一個(gè)面向全國乃至全球的業(yè)務(wù)窗口:建站電話聯(lián)系:18982081108

1.實(shí)驗(yàn)環(huán)境:

vmware虛機(jī)3個(gè)   (虛機(jī)太少了,電腦有點(diǎn)吃力,3個(gè)虛機(jī)只能達(dá)到基本的測試)

系統(tǒng)centos7     (實(shí)驗(yàn)是關(guān)閉防火墻和selinux做的)

MySQL版本5.7

mycat版本1.6

虛機(jī)名字和ip:

mysql1 192.168.211.138

mysql2 192.168.211.139

mysql3 192.168.211.142

mycat安裝在mysql1(192.168.211.138)

這臺(tái)主機(jī)須能夠解析mysql2,mysql3的地址。

可通過/etc/hosts  手動(dòng)添加解析

2.實(shí)驗(yàn)?zāi)康?/p>

實(shí)現(xiàn)mycat讀寫分離和分表的功能。

3.實(shí)驗(yàn)思路

在mycat創(chuàng)建一個(gè)邏輯庫:hello。

創(chuàng)建四個(gè)表格:

t1   這個(gè)表格用來分片,用枚舉的規(guī)則分片。

t2   這個(gè)表格做全局表。

t3   這個(gè)表格做普通表,定義它放到其中一個(gè)datanode,放到mysql1

t4   這個(gè)表格做普通表,定義它放到其中一個(gè)datanode,放到mysql3

虛機(jī)的分配:

mysql1 和mysql2做主從配置,其中mysql1為主,mysql2為從,其中mysql1用來寫,mysql2用來讀。

mysql3 就是個(gè)單獨(dú)的datanode

實(shí)際我們只有兩個(gè)datanode,mysql1,mysql3。

4.實(shí)驗(yàn)步驟

  分別在虛機(jī)安裝mysql5.7,步驟略。

  

  設(shè)置mysql用戶,步驟略。請(qǐng)注意,必須設(shè)置一個(gè)用戶允許內(nèi)網(wǎng)地址連接或者干脆是允許任何地方連接。比如設(shè)置'root'@'%'。

  

  安裝mycat。步驟略。

  配置mysql1和mysql2主從,步驟略。

  

  以上都是些常用配置,懶得特意記錄了。

  以上的環(huán)境都配置好了,就可以開始我們實(shí)驗(yàn)核心步驟mycat的配置了

  

  現(xiàn)在開始整個(gè)過程的配置。

  

  1.在mysql1(192.168.211.138)里創(chuàng)建一個(gè)db1.

mysql> create database db1;
    Query OK, 1 row affected (0.01 sec)

    檢查mysql2(192.168.211.139)里是不是同步了?

    mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1                |
| logs               |
| mysql              |
| performance_schema |
| sys                |
| wordpress          |
+--------------------+
7 rows in set (0.00 sec)

同步了。

2.在mysql3(192.168.211.142)里創(chuàng)建db2。

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db2                |
| logs               |
| mysql              |
| performance_schema |
| sys                |
| wordpress          |
+--------------------+
7 rows in set (0.01 sec)

  3.在mysql1里配置mycat,我的mycat安裝在mysql1。

  我的配置文件路徑:

[root@mysql1 conf]# pwd
/usr/local/mycat/conf

主要配置文件有:

  [root@mysql1 conf]# ls
autopartition-long.txt       log4j2.xml                schema.xml.bk                         server.xml.bk
auto-sharding-long.txt       migrateTables.properties  schema.xml.bk2                        sharding-by-enum.txt
auto-sharding-rang-mod.txt   myid.properties           sequence_conf.properties              wrapper.conf
cacheservice.properties      partition-hash-int.txt    sequence_db_conf.properties           zkconf
dnindex.properties           partition-range-mod.txt   sequence_distributed_conf.properties  zkdownload
ehcache.xml                  rule.xml                  sequence_time_conf.properties
index_to_charset.properties  schema.xml                server.xml
[root@mysql1 conf]#

需要用到的是:schema.xml   ##這個(gè)文件配置分表讀寫分離策略

                 rule.xml     ##這是分表規(guī)則的定義

                 server.xml   ##登錄mycat的賬戶密碼和防火墻的設(shè)置

  4.首先配置:schema.xml

備份下原配置文件:

[root@mysql1 conf]# cp schema.xml schema.xml.bk3

    清空配置文件:

[root@mysql1 conf]# echo " " >schema.xml

重新配置schema.xml,如下是我的配置文件整個(gè)內(nèi)容:

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

	<schema name="hello" checkSQLschema="false" sqlMaxLimit="100">
		<!-- auto sharding by id (long) -->
		<table name="t1" dataNode="dn1,dn2" rule="sharding-by-intfile" />

		<!-- global table is auto cloned to all defined data nodes ,so can join
			with any table whose sharding node is in the same data node -->
		<table name="t2" primaryKey="ID" type="global" dataNode="dn1,dn2" />
		<table name="t3" dataNode="dn1" />
		<table name="t4" dataNode="dn2" />

	</schema>
	<!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743"
		/> -->
	<dataNode name="dn1" dataHost="mysql1" database="db1" />
	<dataNode name="dn2" dataHost="mysql3" database="db2" />

		<dataHost name="mysql1" maxCon="1000" minCon="10" balance="3"
			  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<!-- can have multi write hosts -->
		<writeHost host="hostM1" url="192.168.211.138:3306" user="root"
				   password="Alex2010@">
			<!-- can have multi read hosts -->
			<readHost host="hostS2" url="192.168.211.139:3306" user="root" password="Alex2010@"/>
		</writeHost>
	</dataHost>	

	<dataHost name="mysql3" maxCon="1000" minCon="10" balance="0"
                          writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
                <heartbeat>select user()</heartbeat>
                <!-- can have multi write hosts -->
                <writeHost host="hostM1" url="192.168.211.142:3306" user="root"
                                   password="Alex2010@">
                	<!-- can have multi read hosts -->
			<readHost host="hostS2" url="192.168.211.142:3306" user="root" password="Alex2010@"/>
		</writeHost>
	</dataHost>	

</mycat:schema>

這些字段的解釋,可以查看我前面分片規(guī)則里面的解析。

說明下datahost  balance字段的意義

balance屬性

負(fù)載均衡類型,目前的取值有3種:

1. balance="0", 不開啟讀寫分離機(jī)制,所有讀操作都發(fā)送到當(dāng)前可用的writeHost上。

2. balance="1",全部的readHost與stand by writeHost參與select語句的負(fù)載均衡,簡單的說,當(dāng)雙主雙從模式(M1->S1,M2->S2,并且M1與 

M2互為主備),正常情況下,M2,S1,S2都參與select語句的負(fù)載均衡。

3. balance="2",所有讀操作都隨機(jī)的在writeHost、readhost上分發(fā)。

4. balance="3",所有讀請(qǐng)求隨機(jī)的分發(fā)到wiriterHost對(duì)應(yīng)的readhost執(zhí)行,writerHost不負(fù)擔(dān)讀壓

writeType屬性

負(fù)載均衡類型,目前的取值有3種:

1. writeType="0", 所有寫操作發(fā)送到配置的第一個(gè)writeHost,第一個(gè)掛了切到還生存的第二個(gè)writeHost,重新啟動(dòng)后已切換后的為準(zhǔn),

切換記錄在配置文件中:dnindex.properties .

2. writeType="1",所有寫操作都隨機(jī)的發(fā)送到配置的writeHost,1.5以后廢棄不推薦。

需要說明的是:

	<dataHost name="mysql1" maxCon="1000" minCon="10" balance="3"
			  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<!-- can have multi write hosts -->
		<writeHost host="hostM1" url="192.168.211.138:3306" user="root"
				   password="Alex2010@">
			<!-- can have multi read hosts -->
			<readHost host="hostS2" url="192.168.211.139:3306" user="root" password="Alex2010@"/>
		</writeHost>
	</dataHost>	

讀寫分離這里有兩種寫法:

除了上面的還可以寫下面這樣:

<dataHost name="mysql1" maxCon="1000" minCon="10" balance="3"
			  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<!-- can have multi write hosts -->
		<writeHost host="hostM1" url="192.168.211.138:3306" user="root"
				   password="Alex2010@">
		</writeHost>
		<writeHost host="hostM1" url="192.168.211.139:3306" user="root"
				   password="Alex2010@">
		</writeHost>
	</dataHost>	

區(qū)別是上面的那種寫法,如果主服務(wù)器掛了,從服務(wù)器不能讀了。

 下面的這種寫法,主服務(wù)器掛了,從服務(wù)器依然可以正常讀取。

  這里說一下,后面會(huì)做測試。

  5.看看rule.xml里的配置

     看分表t1的設(shè)置:

<table name="t1" dataNode="dn1,dn2" rule="sharding-by-intfile" />

分表規(guī)則是 sharding-by-intfile

看看這個(gè)的規(guī)則設(shè)置

	<tableRule name="sharding-by-intfile">
		<rule>
			<columns>city</columns>
			<algorithm>hash-int</algorithm>
		</rule>
	</tableRule>

為什么columns是city呢?

這個(gè)city是我設(shè)定的,計(jì)劃創(chuàng)建表格t1(id,name,bu,city)有這四個(gè)列。我準(zhǔn)備用city來做分片的列。

繼續(xù)往下看

     </function>
	<function name="hash-int"
		class="io.mycat.route.function.PartitionByFileMap">
		<property name="mapFile">partition-hash-int.txt</property>
		<property name="type">1</property> 
		<property name="defaultNode">0</property>
	</function>

這是用的hash-int函數(shù)的設(shè)置了。其中mpfile是指要讀取的配置文件。這是什么意思呢?

看看partition-hash-int.txt的內(nèi)容

      [root@mysql1 conf]# cat partition-hash-int.txt 
#10000=0
#10010=1
bj=0
gz=0
sz=1
[root@mysql1 conf]#

我計(jì)劃的表格t1  city列有三個(gè)值,bj   gz   sz  ,這個(gè)設(shè)置的意思是:bj   gz 的數(shù)據(jù)存儲(chǔ)到datanode1也就是mysql1,sz的數(shù)據(jù)存儲(chǔ)

到datanode2也就是mysql3。

      <property name="type">1</property> 
	<property name="defaultNode">0</property>

這兩條參數(shù)也必須要有,type默認(rèn)的值是0,而0的格式是interger,注意我們分片的列是city是字符。

6.配置server.xml,參考下官方教程,很簡單。

7.到這里可以來啟動(dòng)mycat,登錄進(jìn)去創(chuàng)建表格,插入數(shù)據(jù)測試,是不是能夠達(dá)到我們的預(yù)期目標(biāo)?

[root@mysql1 conf]# mysql -uroot -p123456 -P8066 -h 127.0.0.1
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>

登錄進(jìn)來了

mysql> show databases;
+----------+
| DATABASE |
+----------+
| hello    |
+----------+
1 row in set (0.02 sec)

mysql>

我們?cè)O(shè)置的邏輯庫hello

mysql> use hello;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+-----------------+
| Tables in hello |
+-----------------+
| t1              |
| t2              |
| t3              |
| t4              |
+-----------------+
4 rows in set (0.01 sec)

mysql> 

mysql> desc t1;
ERROR 1146 (42S02): Table 'db1.t1' doesn't exist
mysql>

注意這里有個(gè)問題,這些t1-t4的表格,看似是有,其實(shí)是假的。感覺像是BUG。表格需要我們手動(dòng)創(chuàng)建。

創(chuàng)建表格:

   mysql> create table t1 (id int not null,name varchar(15) not null,bu varchar(10) not null,city varchar(5) not null);
Query OK, 0 rows affected (0.36 sec)

    mysql> create table t2 (id int not null,name varchar(15) not null);
Query OK, 0 rows affected (0.10 sec)

    mysql> create table t3 (id int not null,gongzi int not null);
Query OK, 0 rows affected (0.07 sec)

    mysql> create table t4 (id int not null,shui  int not null);
Query OK, 0 rows affected (0.07 sec)

 

    看看創(chuàng)建的表格都放在哪?

    mysql> explain create table t1 (id int not null,name varchar(15) not null,bu varchar(10) not null,city varchar(5) not null);
+-----------+--------------------------------------------------------------------------------------------------------------+
| DATA_NODE | SQL                                                                                                          |
+-----------+--------------------------------------------------------------------------------------------------------------+
| dn1       | create table t1 (id int not null,name varchar(15) not null,bu varchar(10) not null,city varchar(5) not null) |
| dn2       | create table t1 (id int not null,name varchar(15) not null,bu varchar(10) not null,city varchar(5) not null) |
+-----------+--------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql>

這是分片表,dn1,dn2都有

mysql> explain create table t2 (id int not null,name varchar(15) not null);
+-----------+-------------------------------------------------------------+
| DATA_NODE | SQL                                                         |
+-----------+-------------------------------------------------------------+
| dn1       | create table t2 (id int not null,name varchar(15) not null) |
| dn2       | create table t2 (id int not null,name varchar(15) not null) |
+-----------+-------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql>

這是全局表,dn1,dn2都有,全局表的意思是,每個(gè)dn節(jié)點(diǎn)都有的表而且數(shù)據(jù)保持一致。

mysql> explain create table t3 (id int not null,gongzi int not null);
+-----------+-------------------------------------------------------+
| DATA_NODE | SQL                                                   |
+-----------+-------------------------------------------------------+
| dn1       | create table t3 (id int not null,gongzi int not null) |
+-----------+-------------------------------------------------------+
1 row in set (0.00 sec)

mysql>

普通表,預(yù)設(shè)就是放在dn1,正常

mysql> explain create table t4 (id int not null,shui  int not null);
+-----------+------------------------------------------------------+
| DATA_NODE | SQL                                                  |
+-----------+------------------------------------------------------+
| dn2       | create table t4 (id int not null,shui  int not null) |
+-----------+------------------------------------------------------+
1 row in set (0.00 sec)

mysql>

普通表,預(yù)設(shè)就是放在dn2,正常

看看從庫的情況:

mysql> show tables;
+---------------+
| Tables_in_db1 |
+---------------+
| t1            |
| t2            |
| t3            |
+---------------+
3 rows in set (0.00 sec)

mysql>

除了t4沒有,其他都有,正常。

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

    插入t1

    mysql> insert into t1(id,name,bu,city)values(1,'am1','sy','bj');
Query OK, 1 row affected (0.38 sec)

mysql> insert into t1(id,name,bu,city)values(2,'am2','cs','gz');
Query OK, 1 row affected (0.03 sec)

mysql> insert into t1(id,name,bu,city)values(3,'am3','net','sz');
Query OK, 1 row affected (0.08 sec)

mysql>

 插入t2

mysql> insert into t2(id,name)value(4,'am4'),(5,'am5');
Query OK, 2 rows affected (0.11 sec)
Records: 2  Duplicates: 0  Warnings: 0

   

 插入t3

mysql> insert into t3(id,gongzi)values(6,1000),(7,1200);
Query OK, 2 rows affected (0.02 sec)
Records: 2  Duplicates: 0  Warnings: 0

插入t4

mysql> insert into t4(id,shui)values(8,10),(9,8);
Query OK, 2 rows affected (0.04 sec)
Records: 2  Duplicates: 0  Warnings: 0

基礎(chǔ)架構(gòu)和環(huán)境以及達(dá)成,現(xiàn)在來測試:

首先,t1根據(jù)預(yù)設(shè)的目的,bj和gz的數(shù)據(jù)存放在dn1(mysql1),sz的數(shù)據(jù)存放在dn2(mysql3)

mysql> select  * from t1 where city='bj' or city='gz';
+----+------+----+------+
| id | name | bu | city |
+----+------+----+------+
|  1 | am1  | sy | bj   |
|  2 | am2  | cs | gz   |
+----+------+----+------+
2 rows in set (0.10 sec)

mysql> explain select  * from t1 where city='bj' or city='gz';
+-----------+--------------------------------------------------------------+
| DATA_NODE | SQL                                                          |
+-----------+--------------------------------------------------------------+
| dn1       | SELECT * FROM t1 WHERE city = 'bj'  OR city = 'gz' LIMIT 100 |
+-----------+--------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> 

mysql> explain select  * from t1 where city='sz';
+-----------+----------------------------------------------+
| DATA_NODE | SQL                                          |
+-----------+----------------------------------------------+
| dn2       | SELECT * FROM t1 WHERE city = 'sz' LIMIT 100 |
+-----------+----------------------------------------------+
1 row in set (0.02 sec)

mysql>

分表正常

測試讀寫分離

開啟debug日志

<asyncRoot level="debug" includeLocation="true">                 ##默認(rèn)level是info  改成debug后,重啟mycat服務(wù)。

            <AppenderRef ref="Console" />
            <AppenderRef ref="RollingFile"/>

        </asyncRoot>

檢索數(shù)據(jù):

檢索t3的數(shù)據(jù),t3只有mysql1有。

mysql> select * from t3;
+----+--------+
| id | gongzi |
+----+--------+
|  6 |   1000 |
|  7 |   1200 |
+----+--------+
2 rows in set (0.02 sec)

以下是mycat.log日志,可以看到是從mysql2(192.168.211.139)讀取的數(shù)據(jù)

2017-12-15 01:47:23.280 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.server.NonBlockingSession.releaseConnection(NonBlockingSession.java:341))
 - release connection MySQLConnection [id=22, lastTime=1513320443251, user=root, schema=db1, old shema=db1, borrowed=true,
 fromSlaveDB=true, threadId=33, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{SELECT *
FROM t3
LIMIT 100}, respHandler=SingleNodeHandler [node=dn1{SELECT *
FROM t3
LIMIT 100}, packetId=6], host=192.168.211.139, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]


2017-12-15 01:54:37.777 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.server.NonBlockingSession.releaseConnection(NonBlockingSession.java:341)) 
- release connection MySQLConnection [id=26, lastTime=1513320877751, user=root, schema=db1, old shema=db1, borrowed=true, fromSlaveDB=true, 
threadId=31, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{SELECT *
FROM t3
LIMIT 100}, respHandler=SingleNodeHandler [node=dn1{SELECT *
FROM t3
LIMIT 100}, packetId=6], host=192.168.211.139, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
mysql> select * from t1;
+----+------+-----+------+
| id | name | bu  | city |
+----+------+-----+------+
|  3 | am3  | net | sz   |
|  1 | am1  | sy  | bj   |
|  2 | am2  | cs  | gz   |
+----+------+-----+------+
3 rows in set (0.04 sec)

日志

2017-12-15 02:02:35.818 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.MySQLConnection.synAndDoExecute(MySQLConnection.java:448)) 
- con need syn ,total syn cmd 1 commands SET names utf8;schema change:false con:MySQLConnection [id=29, lastTime=1513321355817, user=root, 
schema=db1, old shema=db1, borrowed=true, fromSlaveDB=true, threadId=35, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{SELECT *
FROM t1
LIMIT 100}, respHandler=io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler@11eaaf37, host=192.168.211.139, port=3306, statusSync=null, writeQueue=0, 
modifiedSQLExecuted=false]


2017-12-15 02:02:35.819 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.MySQLConnection.synAndDoExecute(MySQLConnection.java:448)) 
- con need syn ,total syn cmd 1 commands SET names utf8;schema change:false con:MySQLConnection [id=20, lastTime=1513321355819, user=root, 
schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=65, charset=utf8, txIsolation=3, autocommit=true, attachment=dn2{SELECT *
FROM t1
LIMIT 100}, respHandler=io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler@11eaaf37, host=192.168.211.142, port=3306, statusSync=null, writeQueue=0,
 modifiedSQLExecuted=false]

多執(zhí)行幾次檢索存在dn1的數(shù)據(jù),查看日志,可以確認(rèn),數(shù)據(jù)都是從mysql2(192.168.211.139)讀取。實(shí)現(xiàn)了讀寫分離。

8.讀寫兩種不同寫法的測試

前面有提到讀寫分離有兩種寫法,

<dataHost name="mysql1" maxCon="1000" minCon="10" balance="3"
			  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<!-- can have multi write hosts -->
		<writeHost host="hostM1" url="192.168.211.138:3306" user="root"
				   password="Alex2010@">
			<!-- can have multi read hosts -->
			<readHost host="hostS2" url="192.168.211.139:3306" user="root" password="Alex2010@"/>
		</writeHost>
	</dataHost>	

讀寫分離這里有兩種寫法:

除了上面的還可以寫下面這樣:

<dataHost name="mysql1" maxCon="1000" minCon="10" balance="3"
			  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<!-- can have multi write hosts -->
		<writeHost host="hostM1" url="192.168.211.138:3306" user="root"
				   password="Alex2010@">
		</writeHost>
		<writeHost host="hostM1" url="192.168.211.139:3306" user="root"
				   password="Alex2010@">
		</writeHost>
	</dataHost>	

區(qū)別是上面的那種寫法,如果主服務(wù)器掛了,從服務(wù)器不能讀了。

下面的這種寫法,主服務(wù)器掛了,從服務(wù)器依然可以正常讀取。

現(xiàn)在服務(wù)器的寫法是第一種,主服務(wù)器掛了,從服務(wù)器不能讀了。執(zhí)行看看

[root@mysql1 ~]# systemctl stop mysqld.service
[root@mysql1 ~]# systemctl status  mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Fri 2017-12-15 02:16:43 EST; 35s ago
     Docs: man:mysqld(8)
[root@mysql1 ~]# mysql -uroot -p123456 -P8066 -h227.0.0.1
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> select * from t1;
ERROR 3000 (HY000): No MyCAT Database selected
mysql> select * from t1;
ERROR 3000 (HY000): No MyCAT Database selected

確實(shí)無法讀取  

測試第二種

修改schema.xml配置文件

重新啟動(dòng)mysql和mycat 保證環(huán)境正常

正常使用環(huán)境,我們現(xiàn)在關(guān)閉mysql1就是主節(jié)點(diǎn)

[root@mysql1 conf]# systemctl stop mysqld.service
[root@mysql1 conf]# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Fri 2017-12-15 02:23:55 EST; 23s ago
     Docs: man:mysqld(8)

檢索數(shù)據(jù)看看

[root@mysql1 ~]# mysql -uroot -p123456 -P8066 -h227.0.0.1
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> use hello;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from t1;
+----+------+-----+------+
| id | name | bu  | city |
+----+------+-----+------+
|  3 | am3  | net | sz   |
|  1 | am1  | sy  | bj   |
|  2 | am2  | cs  | gz   |
+----+------+-----+------+
3 rows in set (0.46 sec)

果然如此,孰優(yōu)孰劣無須說明了吧。

后記:通過環(huán)境的搭建和簡單的測試,達(dá)到了設(shè)計(jì)的預(yù)期目標(biāo)。

分享名稱:mycat基礎(chǔ)實(shí)驗(yàn)之主從配置讀寫分離和分表
本文鏈接:http://chinadenli.net/article10/jgjego.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、標(biāo)簽優(yōu)化、軟件開發(fā)、品牌網(wǎng)站制作、品牌網(wǎng)站設(shè)計(jì)用戶體驗(yàn)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化
精品人妻一区二区三区四在线| 国内外免费在线激情视频| 日韩女优精品一区二区三区| 国产精品福利一二三区| 天海翼高清二区三区在线| 亚洲一区二区三区在线中文字幕| 五月情婷婷综合激情综合狠狠 | 国产精品久久精品国产| 东京热电东京热一区二区三区| 99视频精品免费视频| 欧美字幕一区二区三区| 在线观看视频成人午夜| 91欧美亚洲精品在线观看| 欧美一区二区黑人在线| 粗暴蹂躏中文一区二区三区| 国产欧美一区二区久久| 欧美三级不卡在线观线看| 五月婷婷综合激情啪啪| 精品香蕉一区二区在线| 少妇人妻无一区二区三区| 国产又大又黄又粗又免费| 老司机精品国产在线视频| 国产精品香蕉免费手机视频| 开心激情网 激情五月天| 日本乱论一区二区三区| 日韩中文字幕人妻精品| 美女黄片大全在线观看| 亚洲欧美天堂精品在线| 97人妻精品免费一区二区| 国产又粗又深又猛又爽又黄| av国产熟妇露脸在线观看| 国产精品一区二区视频| 国产亚洲不卡一区二区| 国产精品欧美激情在线| 粉嫩内射av一区二区| 国产成人亚洲综合色就色| 欧美一级特黄大片做受大屁股| 欧美亚洲综合另类色妞| 性欧美唯美尤物另类视频| 日本免费一级黄色录像| 男人和女人草逼免费视频|