搜尋
首頁資料庫mysql教程mysql分布式中间件cobar

Cobar的分布式主要是通过将表放入不同的库来实现: 1.Cobar支持将一张表水平拆分成多份分别放入不同的库来实现表的水平拆分 2.Cobar也支持将不同的表放入不同的库 3.多数情况下,用户会将以上两种方式混合使用 4.Cobar不支持将一张表,例如test表拆分成test_1

Cobar的分布式主要是通过将表放入不同的库来实现:
     1.Cobar支持将一张表水平拆分成多份分别放入不同的库来实现表的水平拆分
     2.Cobar也支持将不同的表放入不同的库
     3.多数情况下,用户会将以上两种方式混合使用
     4.Cobar不支持将一张表,例如test表拆分成test_1, test_2, test_3.....放在同一个库中,必须将拆分后的表分别放入不同的库来实现分布式


缺点:

    1.不支持跨库的关联操作:join、分页、排序、子查询

    2.不支持SAVEPOINT操作

    3.不支持SET语句的执行,事务和字符集设置语句除外

    4.只支持MySQL数据节点

    5.对于拆分表,插入操作须给出列名,必须包含拆分字段

 

环境规划:

IP                         数据库      表

192.168.1.247        test01       t1

192.168.1.247        test02       t1

192.168.1.247        test03       t1

说明:在本服务器创建三个数据库,数据库中创建相同的表和表类型,将t1表中的数据拆分到teat01,02,03数据库中.

 

1.创建数据库和表

[root@tong1 ~]# /usr/local/mysql-5.6.23/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6028
Server version: 5.6.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> create database test01;                 --创建数据库test01,02,03
Query OK, 1 row affected (0.03 sec)

mysql> create database test02;
Query OK, 1 row affected (0.03 sec)

mysql> create database test03;
Query OK, 1 row affected (0.03 sec)

mysql> \u test01
Database changed
mysql> create table t1(a int,b char(5));        --在三个数据库创建相同的表
Query OK, 0 rows affected (0.34 sec)

mysql> \u test02
Database changed
mysql> create table t1(a int,b char(5));
Query OK, 0 rows affected (0.31 sec)

mysql> \u test03
Database changed
mysql> create table t1(a int,b char(5));
Query OK, 0 rows affected (0.30 sec)

mysql> show tables;
+------------------+
| Tables_in_test03 |
+------------------+
| t1               |
+------------------+
1 row in set (0.00 sec)

mysql> grant all privileges on *.* to tong@'localhost' identified by 'system';
Query OK, 0 rows affected (0.05 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.06 sec)

mysql> exit
Bye
[root@tong1 bin]#

 

2.安装java开发软件包

[root@tong1 ~]# tar xvf jdk-7u71-linux-x64.tar.gz  -C /usr/local/

[root@tong1 ~]# cd /usr/local/

[root@tong1 local]# chown  -R root:root jdk1.7.0_71/

[root@tong1 local]# vim /etc/profile       --添加环境变量

export PATH=$PATH:/usr/local/protobuf-2.5.0/bin:/usr/local/jdk1.7.0_71/bin
export JAVA_HOME=/usr/local/jdk1.7.0_71/
export CLASS_HOME=/usr/local/jdk1.7.0_71/lib

[root@tong1 local]# . /etc/profile

[root@tong1 local]# java -version          --查看java是否安装成功
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
[root@tong1 local]#

 

3.下载安装cobar

下载地址:http://pan.baidu.com/s/1o6igLwY

[root@tong1 ~]# tar xvf cobar-server-1.2.7.tar.gz  -C /usr/local/

[root@tong1 ~]# cd /usr/local/cobar-server-1.2.7/
[root@tong1 cobar-server-1.2.7]# ll
total 36
drwxr-xr-x. 2 root root  4096 Dec 29  2012 bin
drwxr-xr-x. 2 root root  4096 Dec 29  2012 conf
-rwsrwsrwt. 1 root root   575 Dec 29  2012 COPYRIGHT
drwxr-xr-x. 3 root root  4096 May 14 10:13 lib
-rwsrwsrwt. 1 root root 11549 Dec 29  2012 LICENSE
drwxr-xr-x. 2 root root  4096 Dec 29  2012 logs
-rwsrwsrwt. 1 root root   428 Dec 29  2012 README

[root@tong1 cobar-server-1.2.7]# cd conf/
[root@tong1 conf]# ll
total 16
-rw-r--r--. 1 root root 2604 Dec 29  2012 log4j.xml
-rw-r--r--. 1 root root 1262 Dec 29  2012 rule.xml
-rw-r--r--. 1 root root 1966 Dec 29  2012 schema.xml    --mysql数据库的IP,端口
-rw-r--r--. 1 root root 2292 Dec 29  2012 server.xml

[root@tong1 conf]# vim schema.xml


  est" dataNode="test1">        --test架构名,用于用户登陆,test1第一个数据库
   

t1" dataNode="test2,test3" rule="rule1" />   --t1是表名,拆分的表,test2,test3是两个数据库名
 

 

 
  est1">                    --test1是第一个数据库
   
      test[0]dataSourceRef>     --第一个数据库源
   

 

  test2">                             --第二个数据库
   
      test[1]dataSourceRef>
   

 

  test3">                            --第三个数据库
   
      test[2]dataSourceRef>
   

 

 

 
  test" type="mysql">          --test源数据,用于用户登陆
   
      192.168.1.247:3306/test1    --三个数据库服务器和数据库名,数据库也可在不同的服务器上
      192.168.1.247:3306/test2
      192.168.1.247:3306/test3
   

    tong            --用户登陆
    system          --密码
    STRICT_TRANS_TABLES
 

 

[root@tong1 conf]# vim rule.xml

 
 
   
      id
     
   

 

 
 
    2
    512

 

[root@tong1 conf]# vim server.xml

 
 
    8066             --cobar服务启动端口
    9066          --管理端口
    16
    4
    4
    4
    8
    8
    _HEARTBEAT_USER_
    _HEARTBEAT_PASS_
 

 
              --登陆用户名
    system           --密码
    test                 --架构名,用户连接的数据库
 

 

[root@tong1 bin]# ./startup.sh          --启动服务
"/usr/local/jdk1.7.0_71/bin/java" -Dcobar.home="/usr/local/cobar-server-1.2.7" -classpath "/usr/local/cobar-server-1.2.7/conf:/usr/local/cobar-server-1.2.7/lib/classes:/usr/local/cobar-server-1.2.7/lib/cobar-server-1.2.7.jar:/usr/local/cobar-server-1.2.7/lib/log4j-1.2.16.jar" -server -Xms1024m -Xmx1024m -Xmn256m -Xss256k -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:+UseFastAccessorMethods -XX:+DisableExplicitGC -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=75 com.alibaba.cobar.CobarStartup >> "/usr/local/cobar-server-1.2.7/logs/console.log" 2>&1 &

[root@tong1 bin]# cat ../logs/stdout.log     --查看日志

15:33:02,933 INFO  ===============================================
15:33:02,934 INFO  Cobar is ready to startup ...
15:33:02,934 INFO  Startup processors ...
15:33:03,026 INFO  Startup connector ...
15:33:03,031 INFO  Initialize dataNodes ...
15:33:03,051 INFO  test2:0 init success
15:33:03,053 INFO  test1:0 init success
15:33:03,055 INFO  test3:0 init success
15:33:03,066 INFO  CobarManager is started and listening on 9066
15:33:03,068 INFO  CobarServer is started and listening on 8066
15:33:03,071 INFO  ===============================================

[root@tong1 bin]# cat ../logs/console.log

log4j:WARN 2015-05-14 15:33:02 [/usr/local/cobar-server-1.2.7/conf/log4j.xml] load completed.[root@tong1 bin]# netstat -antup | grep java
tcp        0      0 :::8066                     :::*                        LISTEN      25359/java         
tcp        0      0 :::9066                     :::*                        LISTEN      25359/java         
tcp        0      0 ::ffff:192.168.1.247:52451  ::ffff:192.168.1.247:3306   ESTABLISHED 25359/java         
tcp        0      0 ::ffff:192.168.1.247:52450  ::ffff:192.168.1.247:3306   ESTABLISHED 25359/java         
tcp        0      0 ::ffff:192.168.1.247:52452  ::ffff:192.168.1.247:3306   ESTABLISHED 25359/java         
[root@tong1 bin]#

 

4.登陆数据库插入数据(以下红色部分不能少)

[root@tong1 data]# /usr/local/mysql-5.6.23/bin/mysql -h 192.168.1.247 -utong -p -P8066 -Dtest
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.48-cobar-1.2.7 Cobar Server (ALIBABA)

Copyright (c) 2000, 2015, 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> show databases;     --客户端连接的数据库名
+----------+
| DATABASE |
+----------+
| test     |
+----------+
1 row in set (0.00 sec)

mysql> \u test
Database changed
mysql> show tables;        --表名
+----------------+
| Tables_in_test |
+----------------+
| t1             |
+----------------+
2 rows in set (0.00 sec)

mysql> insert into t1 values(1,'c');                --插入数据
Query OK, 2 rows affected (0.14 sec)

mysql> insert into t1 values(2,'z');
Query OK, 2 rows affected (0.20 sec)

mysql> select * from t1;           --不知道为什么test1数据库中有重复的数据
+------+------+
| a    | b    |
+------+------+
|    1 | c    |
|    2 | z    |
|    1 | c    |
|    2 | z    |
+------+------+
4 rows in set (0.01 sec)

mysql>

 

5.在另外两个数据库中查看数据

[root@tong1 bin]# /usr/local/mysql-5.6.23/bin/mysql -u root -p -D test2   --在test2查看数据
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6124
Server version: 5.6.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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;     --有数据
+------+------+
| a    | b    |
+------+------+
|    1 | c    |
|    2 | z    |
+------+------+
3 rows in set (0.00 sec)

mysql> select * from test3.t1;    --在test3数据库查看数据
+------+------+
| a    | b    |
+------+------+
|    1 | c    |
|    2 | z    |
+------+------+
3 rows in set (0.00 sec)

mysql>

 

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
如何識別和優化MySQL中的慢速查詢? (慢查詢日誌,performance_schema)如何識別和優化MySQL中的慢速查詢? (慢查詢日誌,performance_schema)Apr 10, 2025 am 09:36 AM

要優化MySQL慢查詢,需使用slowquerylog和performance_schema:1.啟用slowquerylog並設置閾值,記錄慢查詢;2.利用performance_schema分析查詢執行細節,找出性能瓶頸並優化。

MySQL和SQL:開發人員的基本技能MySQL和SQL:開發人員的基本技能Apr 10, 2025 am 09:30 AM

MySQL和SQL是開發者必備技能。 1.MySQL是開源的關係型數據庫管理系統,SQL是用於管理和操作數據庫的標準語言。 2.MySQL通過高效的數據存儲和檢索功能支持多種存儲引擎,SQL通過簡單語句完成複雜數據操作。 3.使用示例包括基本查詢和高級查詢,如按條件過濾和排序。 4.常見錯誤包括語法錯誤和性能問題,可通過檢查SQL語句和使用EXPLAIN命令優化。 5.性能優化技巧包括使用索引、避免全表掃描、優化JOIN操作和提升代碼可讀性。

描述MySQL異步主奴隸複製過程。描述MySQL異步主奴隸複製過程。Apr 10, 2025 am 09:30 AM

MySQL異步主從復制通過binlog實現數據同步,提升讀性能和高可用性。 1)主服務器記錄變更到binlog;2)從服務器通過I/O線程讀取binlog;3)從服務器的SQL線程應用binlog同步數據。

mysql:簡單的概念,用於輕鬆學習mysql:簡單的概念,用於輕鬆學習Apr 10, 2025 am 09:29 AM

MySQL是一個開源的關係型數據庫管理系統。 1)創建數據庫和表:使用CREATEDATABASE和CREATETABLE命令。 2)基本操作:INSERT、UPDATE、DELETE和SELECT。 3)高級操作:JOIN、子查詢和事務處理。 4)調試技巧:檢查語法、數據類型和權限。 5)優化建議:使用索引、避免SELECT*和使用事務。

MySQL:數據庫的用戶友好介紹MySQL:數據庫的用戶友好介紹Apr 10, 2025 am 09:27 AM

MySQL的安裝和基本操作包括:1.下載並安裝MySQL,設置根用戶密碼;2.使用SQL命令創建數據庫和表,如CREATEDATABASE和CREATETABLE;3.執行CRUD操作,使用INSERT,SELECT,UPDATE,DELETE命令;4.創建索引和存儲過程以優化性能和實現複雜邏輯。通過這些步驟,你可以從零開始構建和管理MySQL數據庫。

InnoDB緩衝池如何工作,為什麼對性能至關重要?InnoDB緩衝池如何工作,為什麼對性能至關重要?Apr 09, 2025 am 12:12 AM

InnoDBBufferPool通過將數據和索引頁加載到內存中來提升MySQL數據庫的性能。 1)數據頁加載到BufferPool中,減少磁盤I/O。 2)臟頁被標記並定期刷新到磁盤。 3)LRU算法管理數據頁淘汰。 4)預讀機制提前加載可能需要的數據頁。

MySQL:初學者的數據管理易用性MySQL:初學者的數據管理易用性Apr 09, 2025 am 12:07 AM

MySQL適合初學者使用,因為它安裝簡單、功能強大且易於管理數據。 1.安裝和配置簡單,適用於多種操作系統。 2.支持基本操作如創建數據庫和表、插入、查詢、更新和刪除數據。 3.提供高級功能如JOIN操作和子查詢。 4.可以通過索引、查詢優化和分錶分區來提升性能。 5.支持備份、恢復和安全措施,確保數據的安全和一致性。

與MySQL中使用索引相比,全表掃描何時可以更快?與MySQL中使用索引相比,全表掃描何時可以更快?Apr 09, 2025 am 12:05 AM

全表掃描在MySQL中可能比使用索引更快,具體情況包括:1)數據量較小時;2)查詢返回大量數據時;3)索引列不具備高選擇性時;4)複雜查詢時。通過分析查詢計劃、優化索引、避免過度索引和定期維護表,可以在實際應用中做出最優選擇。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器