데이터 베이스 MySQL 튜토리얼 mysql分布式中间件cobar

mysql分布式中间件cobar

Jun 07, 2016 pm 02:56 PM
mysql 미들웨어 분산

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으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

PHP에서 MySQL 쿼리 성능을 최적화하는 방법은 무엇입니까? PHP에서 MySQL 쿼리 성능을 최적화하는 방법은 무엇입니까? Jun 03, 2024 pm 08:11 PM

선형 복잡성에서 로그 복잡성까지 조회 시간을 줄이는 인덱스를 구축하여 MySQL 쿼리 성능을 최적화할 수 있습니다. SQL 삽입을 방지하고 쿼리 성능을 향상하려면 PREPAREDStatements를 사용하세요. 쿼리 결과를 제한하고 서버에서 처리되는 데이터의 양을 줄입니다. 적절한 조인 유형 사용, 인덱스 생성, 하위 쿼리 사용 고려 등 조인 쿼리를 최적화합니다. 쿼리를 분석하여 병목 현상을 식별하고, 캐싱을 사용하여 데이터베이스 로드를 줄이고, 오버헤드를 최소화합니다.

PHP에서 MySQL 백업 및 복원을 사용하는 방법은 무엇입니까? PHP에서 MySQL 백업 및 복원을 사용하는 방법은 무엇입니까? Jun 03, 2024 pm 12:19 PM

PHP에서 MySQL 데이터베이스를 백업하고 복원하는 작업은 다음 단계에 따라 수행할 수 있습니다. 데이터베이스 백업: mysqldump 명령을 사용하여 데이터베이스를 SQL 파일로 덤프합니다. 데이터베이스 복원: mysql 명령을 사용하여 SQL 파일에서 데이터베이스를 복원합니다.

PHP를 사용하여 MySQL 테이블에 데이터를 삽입하는 방법은 무엇입니까? PHP를 사용하여 MySQL 테이블에 데이터를 삽입하는 방법은 무엇입니까? Jun 02, 2024 pm 02:26 PM

MySQL 테이블에 데이터를 삽입하는 방법은 무엇입니까? 데이터베이스에 연결: mysqli를 사용하여 데이터베이스에 대한 연결을 설정합니다. SQL 쿼리 준비: 삽입할 열과 값을 지정하는 INSERT 문을 작성합니다. 쿼리 실행: query() 메서드를 사용하여 삽입 쿼리를 실행하면 확인 메시지가 출력됩니다.

MySQL 8.4에서 mysql_native_password가 로드되지 않음 오류를 수정하는 방법 MySQL 8.4에서 mysql_native_password가 로드되지 않음 오류를 수정하는 방법 Dec 09, 2024 am 11:42 AM

MySQL 8.4(2024년 최신 LTS 릴리스)에 도입된 주요 변경 사항 중 하나는 "MySQL 기본 비밀번호" 플러그인이 더 이상 기본적으로 활성화되지 않는다는 것입니다. 또한 MySQL 9.0에서는 이 플러그인을 완전히 제거합니다. 이 변경 사항은 PHP 및 기타 앱에 영향을 미칩니다.

PHP에서 MySQL 저장 프로시저를 사용하는 방법은 무엇입니까? PHP에서 MySQL 저장 프로시저를 사용하는 방법은 무엇입니까? Jun 02, 2024 pm 02:13 PM

PHP에서 MySQL 저장 프로시저를 사용하려면: PDO 또는 MySQLi 확장을 사용하여 MySQL 데이터베이스에 연결합니다. 저장 프로시저를 호출하는 문을 준비합니다. 저장 프로시저를 실행합니다. 결과 집합을 처리합니다(저장 프로시저가 결과를 반환하는 경우). 데이터베이스 연결을 닫습니다.

PHP를 사용하여 MySQL 테이블을 만드는 방법은 무엇입니까? PHP를 사용하여 MySQL 테이블을 만드는 방법은 무엇입니까? Jun 04, 2024 pm 01:57 PM

PHP를 사용하여 MySQL 테이블을 생성하려면 다음 단계가 필요합니다. 데이터베이스에 연결합니다. 데이터베이스가 없으면 작성하십시오. 데이터베이스를 선택합니다. 테이블을 생성합니다. 쿼리를 실행합니다. 연결을 닫습니다.

오라클 데이터베이스와 mysql의 차이점 오라클 데이터베이스와 mysql의 차이점 May 10, 2024 am 01:54 AM

Oracle 데이터베이스와 MySQL은 모두 관계형 모델을 기반으로 하는 데이터베이스이지만 호환성, 확장성, 데이터 유형 및 보안 측면에서 Oracle이 우수하고, MySQL은 속도와 유연성에 중점을 두고 중소 규모 데이터 세트에 더 적합합니다. ① Oracle은 광범위한 데이터 유형을 제공하고, ② 고급 보안 기능을 제공하고, ③ 엔터프라이즈급 애플리케이션에 적합하고, ① MySQL은 NoSQL 데이터 유형을 지원하고, ② 보안 조치가 적고, ③ 중소 규모 애플리케이션에 적합합니다.

Java 프레임워크에서 미들웨어 재사용 및 리소스 공유 관리 Java 프레임워크에서 미들웨어 재사용 및 리소스 공유 관리 Jun 01, 2024 pm 03:10 PM

Java 프레임워크는 다음 전략을 포함하여 미들웨어 재사용 및 리소스 공유를 지원합니다. 연결 풀을 통해 사전 설정된 미들웨어 연결 관리. 스레드 로컬 스토리지를 활용하여 미들웨어 연결을 현재 스레드와 연결합니다. 스레드 풀을 사용하여 재사용 가능한 스레드를 관리합니다. 로컬 또는 분산 캐시를 통해 자주 액세스하는 데이터의 복사본을 저장합니다.

See all articles