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
[root@tong1 conf]# vim rule.xml [root@tong1 conf]# vim server.xml [root@tong1 bin]# ./startup.sh --启动服务 [root@tong1 bin]# cat ../logs/stdout.log --查看日志 15:33:02,933 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 4.登陆数据库插入数据(以下红色部分不能少) [root@tong1 data]# /usr/local/mysql-5.6.23/bin/mysql -h 192.168.1.247 -utong -p -P8066 -Dtest Welcome to the MySQL monitor. Commands end with ; or \g. Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; --客户端连接的数据库名 mysql> \u test mysql> insert into t1 values(1,'c'); --插入数据 mysql> insert into t1 values(2,'z'); mysql> select * from t1; --不知道为什么test1数据库中有重复的数据 mysql> 5.在另外两个数据库中查看数据 [root@tong1 bin]# /usr/local/mysql-5.6.23/bin/mysql -u root -p -D test2 --在test2查看数据 Welcome to the MySQL monitor. Commands end with ; or \g. Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select * from t1; --有数据 mysql> select * from test3.t1; --在test3数据库查看数据 mysql>
t1" dataNode="test2,test3" rule="rule1" /> --t1是表名,拆分的表,test2,test3是两个数据库名
"/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 &
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 ===============================================
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]#
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
Your MySQL connection id is 1
Server version: 5.1.48-cobar-1.2.7 Cobar Server (ALIBABA)
affiliates. Other names may be trademarks of their respective
owners.
+----------+
| DATABASE |
+----------+
| test |
+----------+
1 row in set (0.00 sec)
Database changed
mysql> show tables; --表名
+----------------+
| Tables_in_test |
+----------------+
| t1 |
+----------------+
2 rows in set (0.00 sec)
Query OK, 2 rows affected (0.14 sec)
Query OK, 2 rows affected (0.20 sec)
+------+------+
| a | b |
+------+------+
| 1 | c |
| 2 | z |
| 1 | c |
| 2 | z |
+------+------+
4 rows in set (0.01 sec)
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
Your MySQL connection id is 6124
Server version: 5.6.23-log MySQL Community Server (GPL)
affiliates. Other names may be trademarks of their respective
owners.
+------+------+
| a | b |
+------+------+
| 1 | c |
| 2 | z |
+------+------+
3 rows in set (0.00 sec)
+------+------+
| a | b |
+------+------+
| 1 | c |
| 2 | z |
+------+------+
3 rows in set (0.00 sec)

InnoDBBufferPool通过缓存数据和索引页来减少磁盘I/O,提升数据库性能。其工作原理包括:1.数据读取:从BufferPool中读取数据;2.数据写入:修改数据后写入BufferPool并定期刷新到磁盘;3.缓存管理:使用LRU算法管理缓存页;4.预读机制:提前加载相邻数据页。通过调整BufferPool大小和使用多个实例,可以优化数据库性能。

MySQL与其他编程语言相比,主要用于存储和管理数据,而其他语言如Python、Java、C 则用于逻辑处理和应用开发。 MySQL以其高性能、可扩展性和跨平台支持着称,适合数据管理需求,而其他语言在各自领域如数据分析、企业应用和系统编程中各有优势。

MySQL值得学习,因为它是强大的开源数据库管理系统,适用于数据存储、管理和分析。1)MySQL是关系型数据库,使用SQL操作数据,适合结构化数据管理。2)SQL语言是与MySQL交互的关键,支持CRUD操作。3)MySQL的工作原理包括客户端/服务器架构、存储引擎和查询优化器。4)基本用法包括创建数据库和表,高级用法涉及使用JOIN连接表。5)常见错误包括语法错误和权限问题,调试技巧包括检查语法和使用EXPLAIN命令。6)性能优化涉及使用索引、优化SQL语句和定期维护数据库。

MySQL适合初学者学习数据库技能。1.安装MySQL服务器和客户端工具。2.理解基本SQL查询,如SELECT。3.掌握数据操作:创建表、插入、更新、删除数据。4.学习高级技巧:子查询和窗口函数。5.调试和优化:检查语法、使用索引、避免SELECT*,并使用LIMIT。

MySQL通过表结构和SQL查询高效管理结构化数据,并通过外键实现表间关系。1.创建表时定义数据格式和类型。2.使用外键建立表间关系。3.通过索引和查询优化提高性能。4.定期备份和监控数据库确保数据安全和性能优化。

MySQL是一个开源的关系型数据库管理系统,广泛应用于Web开发。它的关键特性包括:1.支持多种存储引擎,如InnoDB和MyISAM,适用于不同场景;2.提供主从复制功能,利于负载均衡和数据备份;3.通过查询优化和索引使用提高查询效率。

SQL用于与MySQL数据库交互,实现数据的增、删、改、查及数据库设计。1)SQL通过SELECT、INSERT、UPDATE、DELETE语句进行数据操作;2)使用CREATE、ALTER、DROP语句进行数据库设计和管理;3)复杂查询和数据分析通过SQL实现,提升业务决策效率。

MySQL的基本操作包括创建数据库、表格,及使用SQL进行数据的CRUD操作。1.创建数据库:CREATEDATABASEmy_first_db;2.创建表格:CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY,titleVARCHAR(100)NOTNULL,authorVARCHAR(100)NOTNULL,published_yearINT);3.插入数据:INSERTINTObooks(title,author,published_year)VA


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

SublimeText3汉化版
中文版,非常好用

Dreamweaver Mac版
视觉化网页开发工具

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器